Skip to content

Commit f21e19e

Browse files
authored
Breaking: Improved Durable Objects macro (#675)
1 parent 141551a commit f21e19e

File tree

15 files changed

+287
-337
lines changed

15 files changed

+287
-337
lines changed

Cargo.lock

Lines changed: 21 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,7 @@ For more information about how to configure these bindings, see:
221221
### Define a Durable Object in Rust
222222

223223
To define a Durable Object using the `worker` crate you need to implement the `DurableObject` trait
224-
on your own struct. Additionally, the `#[durable_object]` attribute macro must be applied to _both_
225-
your struct definition and the trait `impl` block for it.
224+
on your own struct. Additionally, the `#[durable_object]` attribute macro must be applied to the struct definition.
226225

227226
```rust
228227
use worker::*;
@@ -235,7 +234,6 @@ pub struct Chatroom {
235234
env: Env, // access `Env` across requests, use inside `fetch`
236235
}
237236

238-
#[durable_object]
239237
impl DurableObject for Chatroom {
240238
fn new(state: State, env: Env) -> Self {
241239
Self {
@@ -246,7 +244,7 @@ impl DurableObject for Chatroom {
246244
}
247245
}
248246

249-
async fn fetch(&mut self, _req: Request) -> Result<Response> {
247+
async fn fetch(&self, _req: Request) -> Result<Response> {
250248
// do some work when a worker makes a request to this DO
251249
Response::ok(&format!("{} active users.", self.users.len()))
252250
}
@@ -283,7 +281,6 @@ pub struct SqlCounter {
283281
sql: SqlStorage,
284282
}
285283

286-
#[durable_object]
287284
impl DurableObject for SqlCounter {
288285
fn new(state: State, _env: Env) -> Self {
289286
let sql = state.storage().sql();

0 commit comments

Comments
 (0)