On Tue, Nov 12, 2013 at 02:51:53PM +0200, Oren Ben-Kiki wrote:
> First, if the array holds values (as opposed to pointers to values), then
> pretty much your only option is to replace your pointers with indices to
> the array. You'd need access to the container to access the values, of
> course. But this is the only safe way because adding into the array may
> relocate it, invalidating all pointers.

Using newtype'd indices is my personal preference at the moment. I
find it works out quite elegantly in practice for self-contained data
structures.

> I wish there was a way to say "this borrowed pointer lives only as
> long as its container". That doesn't seem to be in the cards though
> :-(

I wouldn't go that far. I do hope for us to solve this elegantly in
the future. But it's true that there is enough on our plate and I don't
want to think it right now. But we basically covered this in prior
threads, iirc. [1, 2]

The idea of a lifetime that means "as long as the struct it is
attached to" is a solid one, but I don't think we can do that AND
permit the struct to be moved without something like the `Message` [1]
type I sketched out. Otherwise I don't know how we could guarantee
that there are no outstanding borrowed pointers at the time of move --
well, I take that back: we could possibly permit `return` statements
that exit the struct's current scope, but that's it.


Niko

[1] https://mail.mozilla.org/pipermail/rust-dev/2013-November/006304.html
[2] https://mail.mozilla.org/pipermail/rust-dev/2013-October/006172.html
    For some reason, I can't find a link in the archives to the message that
    I sent, only Oren's reply, but you can see it quoted below.
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to