Kimundi / owning-ref-rs

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

Possible approach to fix #71 #72

Open steffahn opened 3 years ago

steffahn commented 3 years ago

Resolves #71.

steffahn commented 3 years ago

Only a draft since this does not explain the lifetime parameter in the documentation and since it isn’t clear whether an alternative solution with

pub struct OwningRef_<'t, O, T: ?Sized> {
    owner: O,
    reference: *const T,
    marker: PhantomData<&'t T>,
}
type OwningRef<O, T: ?Sized> = OwningRef_<'static, O, T>;

would be better (e.g. to reduce breakage). This would, effectlively, be like restricting OwningRef<O, T: ?Sized> to T: 'static (while also providing a more general version).

And it’s not clear what the best choice for more vs. less lifetime parameters for all the type synonyms is. This PR so far took the approach of avoiding implicit 'statics, but also avoiding confusion by having multiple type parameters for e.g. RefRef. Note that the type synonyms are for the common case only, so having them be somewhat restricted w.r.t. lifetimes would still allow people to use the underlying OwningRef/OwningRef_-based explicit type—with all the lifetimes—anyways.