Defining A DynamicVector containing References
I am trying to create a vector that holds a list of object references so that I can manipulate the object's properties from the container but I don't understand how to define the "lifetime" of the Reference type. According to the Mojo docs, it requires three parameters (Reference[?, ?, ?]). I want the lifetime to last for the duration of the parent object's lifetime. Can I get some examples for proper lifetime values when specifying the Reference type parameters?
4 Replies
We'll enhance
Reference
in upcoming releases. Right now, it's very difficult to use and has internal usage only. In the meantime, I recommend working with a vec of pointers so that Reference
, borrow checker etc. become mature enough.I think you would probably want your vector to own the original objects and then it can use
__refitem__
to return your References. I am not 100% clear on what you are trying to achieve but there are some examples of using References and linking them to lifetimes here.
But for a lot of uses Ehsan is probably correct, though some cool stuff is already possible.Unfortunately, refitem isn't intended for such use yet.
Congrats @Ehsan M. Kermani, you just advanced to level 3!