Kimundi / owning-ref-rs

A library for creating references that carry their owner with them.
MIT License
361 stars 50 forks source link

Method to clone owner when it implements CloneStableAddress #70

Open dbeckwith opened 4 years ago

dbeckwith commented 4 years ago

It would be nice to be able to convert OwningRef<&O, T> to OwningRef<O, T> when O: CloneStableAddress. Example:

impl<O, T> OwningRef<&O, T>
where
    O: CloneStableAddress,
{
    pub fn clone_owner(&self) -> OwningRef<O, T> {
        // SAFETY: safe because the owner implements CloneStableAddress
        unsafe { self.map_owner(Clone::clone) }
    }
}