Skip to content

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

@eric-seppanen

Description

@eric-seppanen

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions