M
Modular7mo ago
swig.

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?
Reference[Snake, __mlir_attr.`true`, ImmLifetime.DType]
Reference[Snake, __mlir_attr.`true`, ImmLifetime.DType]
4 Replies
Ehsan M. Kermani (Modular)
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.
Michael K
Michael K7mo ago
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.
Ehsan M. Kermani (Modular)
Unfortunately, refitem isn't intended for such use yet.
ModularBot
ModularBot7mo ago
Congrats @Ehsan M. Kermani, you just advanced to level 3!
Want results from more Discord servers?
Add your server