#Defining A DynamicVector containing References

4 messages · Page 1 of 1 (latest)

abstract umbra
#

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]

snow vale
#

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.

errant needle
#

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.

snow vale
#

Unfortunately, refitem isn't intended for such use yet.