Skip to content
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

Using #[durable_object] more than once causes a compile error #432

Open
1 task done
eric-seppanen opened this issue Jan 10, 2024 · 0 comments
Open
1 task done

Using #[durable_object] more than once causes a compile error #432

eric-seppanen opened this issue Jan 10, 2024 · 0 comments

Comments

@eric-seppanen
Copy link
Contributor

Is there an existing issue for this?

  • I have searched the existing issues

What version of workers-rs are you using?

0.0.18

What version of wrangler are you using?

3.22.3

Describe the bug

Attempting to declare multiple #[durable_object] structs in the same module always results in a compile error.

Furthermore, there is no documentation on the macro so it's not clear how it is supposed to be used.

Steps To Reproduce

Example code:

use worker::{durable_object, Env, Request, Response};

#[durable_object]
pub struct One {
    counter: u32,
}

#[durable_object]
impl DurableObject for One {
    fn new(state: State, env: Env) -> Self {
        Self {
            counter: 0,
        }
    }

    async fn fetch(&mut self, req: Request) -> worker::Result<Response> {
        Response::ok("one")
    }
}

#[durable_object]
pub struct Two {
    counter: u32,
}

#[durable_object]
impl DurableObject for Two {
    fn new(state: State, env: Env) -> Self {
        Self {
            counter: 0,
        }
    }

    async fn fetch(&mut self, req: Request) -> worker::Result<Response> {
        Response::ok("one")
    }
}

wrangler dev or wrangler deploy always results in a rust compiler error, because the macro apparently emits the same symbols each time it's invoked.

error[E0428]: the name `__Need_Durable_Object_Trait_Impl_With_durable_object_Attribute` is defined multiple times
  --> src/durable.rs:90:1
   |
72 | #[durable_object]
   | ----------------- previous definition of the trait `__Need_Durable_Object_Trait_Impl_With_durable_object_Attribute` here
...
90 | #[durable_object]
   | ^^^^^^^^^^^^^^^^^ `__Need_Durable_Object_Trait_Impl_With_durable_object_Attribute` redefined here
   |
   = note: `__Need_Durable_Object_Trait_Impl_With_durable_object_Attribute` must be defined only once in the type namespace of this module
   = note: this error originates in the attribute macro `durable_object` (in Nightly builds, run with -Z macro-backtrace for more info)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant