We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
get
1 parent 56f7fce commit 04f6257Copy full SHA for 04f6257
2 files changed
crates/rust/src/interface.rs
@@ -2735,7 +2735,7 @@ impl<'a> {camel}Borrow<'a>{{
2735
}}
2736
2737
/// Gets access to the underlying `T` in this resource.
2738
- pub fn get<T: Guest{camel}>(&self) -> &T {{
+ pub fn get<T: Guest{camel}>(&self) -> &'a T {{
2739
let ptr = unsafe {{ &mut *self.as_ptr::<T>() }};
2740
ptr.as_ref().unwrap()
2741
tests/runtime/resource-borrow/test.rs
@@ -10,11 +10,15 @@ pub struct MyThing {
10
val: u32,
11
}
12
13
+fn get_val<'a>(v: &ThingBorrow<'a>) -> &'a u32 {
14
+ &v.get::<MyThing>().val
15
+}
16
+
17
impl Guest for Test {
18
type Thing = MyThing;
19
20
fn foo(v: ThingBorrow<'_>) -> u32 {
- v.get::<MyThing>().val + 2
21
+ get_val(&v) + 2
22
23
24
0 commit comments