Skip to content

Commit 023e4e0

Browse files
authored
FAQ: wrong Ref usage, missing expect() call (#76)
* FAQ: Added unwraping after `cast` call, so it compiles correctly. * Adjusted Rust class to `Option<Instance<T>>` so it fits with tutorial and compiles properly
1 parent 98a0eaa commit 023e4e0

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/faq/code.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ struct MyNode {
392392
// late-initialization is modeled with Option
393393
// the Default derive will initialize both to None
394394
node2d: Option<Ref<Node>>,
395-
instance: Option<Ref<MyClass>>,
395+
instance: Option<Instance<MyClass>>,
396396
}
397397

398398
#[methods]
@@ -404,7 +404,8 @@ impl MyNode {
404404
.get_node("Node2D")
405405
.expect("this node must have a child with the path `Node2D`");
406406
let node2d = unsafe { node2d.assume_safe() };
407-
let node2d = node2d.cast::<Node2D>();
407+
let node2d = node2d.cast::<Node2D>()
408+
.expect("child must be of type 'Node2D'");
408409
self.node2d = Some(node2d.claim());
409410

410411
// Get an existing child node that is a Rust class.

0 commit comments

Comments
 (0)