@@ -221,8 +221,7 @@ For more information about how to configure these bindings, see:
221
221
### Define a Durable Object in Rust
222
222
223
223
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.
226
225
227
226
``` rust
228
227
use worker :: * ;
@@ -235,7 +234,6 @@ pub struct Chatroom {
235
234
env : Env , // access `Env` across requests, use inside `fetch`
236
235
}
237
236
238
- #[durable_object]
239
237
impl DurableObject for Chatroom {
240
238
fn new (state : State , env : Env ) -> Self {
241
239
Self {
@@ -246,7 +244,7 @@ impl DurableObject for Chatroom {
246
244
}
247
245
}
248
246
249
- async fn fetch (& mut self , _req : Request ) -> Result <Response > {
247
+ async fn fetch (& self , _req : Request ) -> Result <Response > {
250
248
// do some work when a worker makes a request to this DO
251
249
Response :: ok (& format! (" {} active users." , self . users. len ()))
252
250
}
@@ -283,7 +281,6 @@ pub struct SqlCounter {
283
281
sql : SqlStorage ,
284
282
}
285
283
286
- #[durable_object]
287
284
impl DurableObject for SqlCounter {
288
285
fn new (state : State , _env : Env ) -> Self {
289
286
let sql = state . storage (). sql ();
0 commit comments