-
Notifications
You must be signed in to change notification settings - Fork 354
update examples and usage for wasm_bindgen #868
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
I believe I fixed this in #816, released in worker 0.6.4. Are you seeing this in that version or above or an earlier version? |
|
I was seeing this on 0.6.7 but I can check in 0.6.4 as well. For reference, here is my full on worker 0.6.7: use worker::{durable_object, event, wasm_bindgen, Env, Request, Response, Result, State};
type User = String;
type Message = String;
#[durable_object]
pub struct Chatroom {
users: Vec<User>,
messages: Vec<Message>,
state: State,
env: Env, // access `Env` across requests, use inside `fetch`
}
impl DurableObject for Chatroom {
fn new(state: State, env: Env) -> Self {
Self {
users: vec![],
messages: vec![],
state: state,
env,
}
}
async fn fetch(&self, _req: Request) -> Result<Response> {
// do some work when a worker makes a request to this DO
Response::ok(&format!("{} active users.", self.users.len()))
}
}
#[event(fetch)]
async fn fetch(req: Request, env: Env, _ctx: worker::Context) -> Result<Response> {
let ns = env.durable_object("CHATROOM")?;
let stub = ns.id_from_name("chatroom-1")?.get_stub()?;
stub.fetch_with_request(req).await
} |
|
Same error with same code but using worker v0.6.4: worker 0.6.4 (same code) error: just a quick check to make sure I'm using the right version in my gives: |
|
I just copied and pasted your exact code example into a test project with this Cargo.toml: and this wrangler.toml and it works fine for me via Let me know if that works for you, or please share replication instructions further. |
on new project creation, if we use the #[durable_object] attribute the macro expansion fails because wasm-bindgen must be included as a dependency.
cc44a54 to
a281b98
Compare
|
Thanks, just checked on v0.6.4 and v0.6.7 with the updated Project.toml - Looks like it's working for both of those versions without I've pushed a new commit to this pr that just updates the templates, not sure if this is the direction you'd want to take. |
|
Since I was able to reproduce locally, if my changes to the templates are not warranted this pull request can be closed. |
|
It looks like #816 isn't quite right if this is needed. I think that macro fix needs to be changed to use |
|
I think you're right, I remember viewing this PR while I was trying to figure out what was wrong. I could not tell because I don't have a ton of experience with debugging rust macros/rust macros in general. I can give it a go |
|
Thanks for your feedback and thought on this - I've posted #869 which should fix this but please let me know if you see any further issues. |
|
Thanks, this change fixed the issue on the latest version. Closing this PR because of change in #869 |
Issue found when trying to implement an example similar to the one listed in the README. A change in the
durable_objectmacro I believe now makes it so that including wasm_bindgen seems to be required. If not included, a confusing error occurs that is difficult to debug, likely from macro expansion. See error attached below.