No recommended way to call Base<T>
methods from init
#585
Labels
status: duplicate
This issue or pull request already exists
Basically what I want to achieve is to have fully constructed tree after
init
finishes.I'd also would like to avoid
ready
because:init
outside ofSelf
fieldsready
can be called multiple times if object is readded to the tree so more logic needs to be added to handle thisGd::from_init_fn
also doesn't help because nodes must haveinit
method to be usabled in the editor.Problem
This code crashes:
Workaround
I can use a different method to achieve it which doesn't crash:
But...
Base::to_gd
is#[doc(hidden)]
and also is not recommended to use:Also from The Book
Question
Is there any suggested way to achieve mentioned functionality? It might be that Base has some magical functions but RustRover just doesn't display it to me:

Solution 1 (more lazy, less ideal)
Just make
Base::to_gd
/Base::as_gd
a public API.In that case it would also make sense to add
Deref
/DerefMut
andBase::as_gd_mut
.This is probably the least preferred way becausee we are working with half-constructed
Base
node instead of fully constructedSelf
node.Solution 2
Adding additional overload for
init
in theory is the best alternative:Solution 3
I don't know if it will work but still an alternative:
The text was updated successfully, but these errors were encountered: