You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: worker-sandbox/src/durable.rs
+27-11Lines changed: 27 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
use serde::Serialize;
1
+
use serde::{Deserialize,Serialize};
2
2
use std::convert::TryFrom;
3
3
use std::{cell::RefCell, collections::HashMap};
4
4
@@ -11,16 +11,20 @@ use worker::{
11
11
12
12
#[durable_object]
13
13
pubstructMyClass{
14
-
name:String,
15
14
state:State,
16
15
number:RefCell<usize>,
17
16
}
18
17
18
+
#[derive(Deserialize)]
19
+
pubstructQueryParams{
20
+
name:String,
21
+
}
22
+
19
23
implDurableObjectforMyClass{
20
24
fnnew(state:State,_env:Env) -> Self{
21
-
let name = state.id().name().unwrap_or_else(|| state.id().to_string());
25
+
// Unfortunately we can't access the `name` property within the Durable Object (see <https://github.com/cloudflare/workerd/issues/2240>). Instead, we can pass it as a request parameter.
26
+
assert!(state.id().name().is_none());
22
27
Self{
23
-
name,
24
28
state,
25
29
number:RefCell::new(0),
26
30
}
@@ -30,7 +34,10 @@ impl DurableObject for MyClass {
Copy file name to clipboardExpand all lines: worker/src/durable.rs
+1Lines changed: 1 addition & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -179,6 +179,7 @@ impl ObjectId<'_> {
179
179
180
180
/// The name that was used to create the `ObjectId` via [`id_from_name`](https://developers.cloudflare.com/durable-objects/api/namespace/#idfromname).
181
181
/// `None` is returned if the `ObjectId` was constructed using [`unique_id`](https://developers.cloudflare.com/durable-objects/api/namespace/#newuniqueid).
182
+
/// `None` is also returned within the Durable Object constructor, as the `name` property is not accessible there (see <https://github.com/cloudflare/workerd/issues/2240>).
0 commit comments