I just had an idea for an owning pointer in an ownership/borrow system. Would it be possible to have something like
&own T in Rust or any future language that is based on ownership and borrowing. This could express ownership without having to move the value. My thought was that it might could be an alternative to
Box but doesn't have to be allocated on the heap.
How is this different than
&mut T? You couldn't re borrow T. When it's lifetime ends, it drops T. You could also move T out of the reference ending the reference's lifetime.
Why would this be helpful? That is kind of my question. But ideas I had:
- LinkedList without the heap. These may not be that helpful. For example, I don't think you could push items onto it in a loop. Also maybe a bad api:
- Not having to move large items.
&mut Tmight already solved 99% of that use case.
- Make self referring types easier?
&own Twould then need to know if it is allocated on the heap or not so it can clean up memory properly. What would the lifetime be?
'static? Would Rust need a
Movetrait to make this work because you would have to de allocate when you move T out of the reference?
Do y'all think this would make sense with ownership and borrowing? Do you think it would be useful?