Struct rental::common::RentRef[][src]

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

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

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

Methods

impl<H: 'static + StableDeref, T: 'static> RentRef<H, 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.

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.

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.

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.

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.

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.

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.

Important traits for &'a mut R

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.

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.

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.

Important traits for &'a mut R

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.

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.

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.

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

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

Return a shared reference to the head field of the struct.

Execute a closure on shared borrows of the fields of the struct.

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

Important traits for &'a mut R

Return a shared reference from shared borrows of the fields of the struct.

This is a subtle variation of rent_all 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.

Optionally return a shared reference from shared borrows of the fields of the struct.

This is a subtle variation of rent_all 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.

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

This is a subtle variation of rent_all 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.

Execute a closure on shared borrows of the prefix fields and a mutable borrow of the suffix field of the struct.

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

Important traits for &'a mut R

Return a mutable reference from shared borrows of the prefix fields and a mutable borrow of the suffix field of the struct.

This is a subtle variation of rent_all_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.

Optionally return a mutable reference from shared borrows of the prefix fields and a mutable borrow of the suffix field of the struct.

This is a subtle variation of rent_all_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.

Try to return a mutable reference from shared borrows of the prefix fields and a mutable borrow of the suffix field of the struct, or an error on failure.

This is a subtle variation of rent_all_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.

impl<H: 'static + StableDeref, T: 'static> RentRef<H, T>
[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.

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, T: 'static> RentRef<H, T>
[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.

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.

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, T: 'static> Debug for RentRef<H, T> where
    H: Debug,
    &'static T: Debug
[src]

Formats the value using the given formatter. Read more

impl<H: 'static + StableDeref, T: 'static> Clone for RentRef<H, T> where
    H: CloneStableDeref,
    &'static T: Clone
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

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

The resulting type after dereferencing.

Dereferences the value.

impl<H: 'static + StableDeref, T: 'static> AsRef<Self::Target> for RentRef<H, T>
[src]

Performs the conversion.

Auto Trait Implementations

impl<H, T> Send for RentRef<H, T> where
    H: Send,
    T: Sync

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