[][src]Struct rental::common::RentMut

pub struct RentMut<H: 'static + StableDeref + DerefMut, T: 'static> { /* fields omitted */ }

Stores an owner and a mutable reference in the same struct.

let mut r = RentMut::new(Box::new(5), |i| &mut *i);
*r = 12;
assert_eq!(12, RentMut::rent(&mut r, |iref| **iref));

Methods

impl<H: 'static + StableDeref + DerefMut, T: 'static> RentMut<H, T>[src]

pub fn new<__Fsuffix>(head: H, suffix: __Fsuffix) -> Self where
    __Fsuffix: for<'head> FnOnce(&'head mut <H as Deref>::Target) -> &'head mut T, 
[src]

Create a new instance of the rental struct.

The first argument provided is the head, followed by a series of closures, one for each tail field. Each of these closures will receive, as its arguments, a borrow of the previous field, followed by borrows of the remaining prefix fields if the struct is a shared rental. If the struct is a mutable rental, only the immediately preceding field is passed.

pub fn try_new<__Fsuffix, __E>(
    head: H,
    suffix: __Fsuffix
) -> RentalResult<Self, __E, H> where
    __Fsuffix: for<'head> FnOnce(&'head mut <H as Deref>::Target) -> Result<&'head mut T, __E>, 
[src]

Attempt to create a new instance of the rental struct.

As new, but each closure returns a Result. If one of them fails, execution is short-circuited and a tuple of the error and the original head value is returned to you.

pub fn try_new_or_drop<__Fsuffix, __E>(
    head: H,
    suffix: __Fsuffix
) -> Result<Self, __E> where
    __Fsuffix: for<'head> FnOnce(&'head mut <H as Deref>::Target) -> Result<&'head mut T, __E>, 
[src]

Attempt to create a new instance of the rental struct.

As try_new, but only the error value is returned upon failure; the head value is dropped. This method interacts more smoothly with existing error conversions.

pub unsafe fn all_erased(_self: &Self) -> Self::Borrow[src]

Return lifetime-erased shared borrows of the fields of the struct.

This is unsafe because the erased lifetimes are fake. Use this only if absolutely necessary and be very mindful of what the true lifetimes are.

pub unsafe fn all_mut_erased(_self: &mut Self) -> Self::BorrowMut[src]

Return a lifetime-erased mutable borrow of the suffix of the struct.

This is unsafe because the erased lifetimes are fake. Use this only if absolutely necessary and be very mindful of what the true lifetimes are.

pub fn rent<__F, __R>(_self: &Self, f: __F) -> __R where
    __F: for<'suffix, 'head> FnOnce(&'suffix &'head mut T) -> __R,
    __R: , 
[src]

Execute a closure on the shared suffix of the struct.

The closure may return any value not bounded by one of the special rentail lifetimes of the struct.

pub fn rent_mut<__F, __R>(_self: &mut Self, f: __F) -> __R where
    __F: for<'suffix, 'head> FnOnce(&'suffix mut &'head mut T) -> __R,
    __R: , 
[src]

Execute a closure on the mutable suffix of the struct.

The closure may return any value not bounded by one of the special rentail lifetimes of the struct.

pub fn ref_rent<__F, __R>(_self: &Self, f: __F) -> &__R where
    __F: for<'suffix, 'head> FnOnce(&'suffix &'head mut T) -> &'suffix __R,
    __R: ?Sized
[src]

Return a shared reference from the shared suffix of the struct.

This is a subtle variation of rent where it is legal to return a reference bounded by a rental lifetime, because that lifetime is reborrowed away before it is returned to you.

pub fn maybe_ref_rent<__F, __R>(_self: &Self, f: __F) -> Option<&__R> where
    __F: for<'suffix, 'head> FnOnce(&'suffix &'head mut T) -> Option<&'suffix __R>,
    __R: ?Sized
[src]

Optionally return a shared reference from the shared suffix of the struct.

This is a subtle variation of rent where it is legal to return a reference bounded by a rental lifetime, because that lifetime is reborrowed away before it is returned to you.

pub fn try_ref_rent<__F, __R, __E>(_self: &Self, f: __F) -> Result<&__R, __E> where
    __F: for<'suffix, 'head> FnOnce(&'suffix &'head mut T) -> Result<&'suffix __R, __E>,
    __R: ?Sized
[src]

Try to return a shared reference from the shared suffix of the struct, or an error on failure.

This is a subtle variation of rent where it is legal to return a reference bounded by a rental lifetime, because that lifetime is reborrowed away before it is returned to you.

pub fn ref_rent_mut<__F, __R>(_self: &mut Self, f: __F) -> &mut __R where
    __F: for<'suffix, 'head> FnOnce(&'suffix mut &'head mut T) -> &'suffix mut __R,
    __R: ?Sized
[src]

Return a mutable reference from the mutable suffix of the struct.

This is a subtle variation of rent_mut where it is legal to return a reference bounded by a rental lifetime, because that lifetime is reborrowed away before it is returned to you.

pub fn maybe_ref_rent_mut<__F, __R>(
    _self: &mut Self,
    f: __F
) -> Option<&mut __R> where
    __F: for<'suffix, 'head> FnOnce(&'suffix mut &'head mut T) -> Option<&'suffix mut __R>,
    __R: ?Sized
[src]

Optionally return a mutable reference from the mutable suffix of the struct.

This is a subtle variation of rent_mut where it is legal to return a reference bounded by a rental lifetime, because that lifetime is reborrowed away before it is returned to you.

pub fn try_ref_rent_mut<__F, __R, __E>(
    _self: &mut Self,
    f: __F
) -> Result<&mut __R, __E> where
    __F: for<'suffix, 'head> FnOnce(&'suffix mut &'head mut T) -> Result<&'suffix mut __R, __E>,
    __R: ?Sized
[src]

Try to return a mutable reference from the mutable suffix of the struct, or an error on failure.

This is a subtle variation of rent_mut where it is legal to return a reference bounded by a rental lifetime, because that lifetime is reborrowed away before it is returned to you.

pub fn into_head(_self: Self) -> H[src]

Drop the rental struct and return the original head value to you.

impl<H: 'static + StableDeref + DerefMut, T: 'static> RentMut<H, T>[src]

pub fn all<'__s>(_self: &'__s Self) -> Self::Borrow[src]

Borrow all fields of the struct by reborrowing away the rental lifetimes.

This is safe because the lifetimes are verified to be covariant first.

pub fn suffix(_self: &Self) -> <Self::Borrow as IntoSuffix>::Suffix[src]

Borrow the suffix field of the struct by reborrowing away the rental lifetimes.

This is safe because the lifetimes are verified to be covariant first.

impl<H: 'static + StableDeref + DerefMut, T: 'static> RentMut<H, T>[src]

pub fn map<__U: 'static, __F>(_self: Self, __f: __F) -> RentMut<H, __U> where
    __F: for<'suffix, 'head> FnOnce(&'head mut T) -> &'head mut __U, 
[src]

Maps the suffix field of the rental struct to a different type.

Consumes the rental struct and applies the closure to the suffix field. A new rental struct is then constructed with the original prefix and new suffix.

pub fn try_map<__U: 'static, __F, __E>(
    _self: Self,
    __f: __F
) -> RentalResult<RentMut<H, __U>, __E, H> where
    __F: for<'suffix, 'head> FnOnce(&'head mut T) -> Result<&'head mut __U, __E>, 
[src]

Try to map the suffix field of the rental struct to a different type.

As map, but the closure may fail. Upon failure, the tail is dropped, and the error is returned to you along with the head.

pub fn try_map_or_drop<__U: 'static, __F, __E>(
    _self: Self,
    __f: __F
) -> Result<RentMut<H, __U>, __E> where
    __F: for<'suffix, 'head> FnOnce(&'head mut T) -> Result<&'head mut __U, __E>, 
[src]

Try to map the suffix field of the rental struct to a different type.

As map, but the closure may fail. Upon failure, the struct is dropped and the error is returned.

Trait Implementations

impl<H: 'static + StableDeref + DerefMut, T: 'static> AsMut<<RentMut<H, T> as Deref>::Target> for RentMut<H, T>[src]

impl<H: 'static + StableDeref + DerefMut, T: 'static> AsRef<<RentMut<H, T> as Deref>::Target> for RentMut<H, T>[src]

impl<H: 'static + StableDeref + DerefMut, T: 'static> Debug for RentMut<H, T> where
    &'static mut T: Debug
[src]

impl<H: 'static + StableDeref + DerefMut, T: 'static> Deref for RentMut<H, T>[src]

type Target = <&'static mut T as Deref>::Target

The resulting type after dereferencing.

impl<H: 'static + StableDeref + DerefMut, T: 'static> DerefMut for RentMut<H, T>[src]

Auto Trait Implementations

impl<H, T> Send for RentMut<H, T> where
    H: Send,
    T: Send

impl<H, T> Sync for RentMut<H, T> where
    H: Sync,
    T: Sync

Blanket Implementations

impl<T> From for T[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]