Trait rental::Rental
[−]
[src]
pub unsafe trait Rental { type Owner: FixedDeref; type Rental; unsafe fn rental(&self) -> &Self::Rental; fn from_parts(Self::Owner, Self::Rental) -> Self; unsafe fn into_parts(self) -> (Self::Owner, Self::Rental); fn into_owner(self) -> Self::Owner; }
This trait is implement for all generated rental types.
It contains within everything that is possible to express without HKT. The
most important methods can't be expressed here, but can be seen on the
predefined RentRef
and
RentMut
structs.
Associated Types
type Owner: FixedDeref
type Rental
Required Methods
unsafe fn rental(&self) -> &Self::Rental
This returns to you the rented value outside of an existential closure.
This is unsafe because the lifetime substituted for 'rental
here is a
lie and does not reflect the true lifetime of the value. Only use this
if you have no alternative, and think very carefully about how you're
using the value to prevent it from outliving the rental struct, or
inserting into it data that will not live long enough.
fn from_parts(Self::Owner, Self::Rental) -> Self
This will produce a rental struct from component parts. Not unsafe because, if you already have the components safely, combining them in this way does not introduce any additional unsafety.
unsafe fn into_parts(self) -> (Self::Owner, Self::Rental)
This will decompose a rental struct into its component parts. This is obviously unsafe because one may drop the owner while retaining the borrow.
fn into_owner(self) -> Self::Owner
This sill consume a rental struct and return to you the owner, discarding the rented value.
Implementors
impl<'rental, T: FixedDeref + 'rental, B: ?Sized + 'rental> Rental for RentRef<'rental, T, B> where T: FixedDeref
impl<'rental, T: FixedDeref + DerefMut + 'rental, B: ?Sized + 'rental> Rental for RentMut<'rental, T, B> where T: FixedDeref + DerefMut