Struct rental::examples::RentMutMap
[−]
[src]
pub struct RentMutMap<T: 'static, U: 'static, V: 'static> { /* fields omitted */ }
An example that borrows mutably off of another rental struct.
let mut r = RentMut::new(Box::new(5), |i| &mut *i); let mut rm = RentMutMap::new(Box::new(r), |r| &mut **r.suffix); *rm = 12; assert_eq!(12, rm.rent(|iref| **iref));
Methods
impl<T: 'static, U: 'static, V: 'static> RentMutMap<T, U, V>
[src]
fn new<__Fsuffix>(head: Box<RentMut<T, U>>, suffix: __Fsuffix) -> Self where
__Fsuffix: for<'head_0, 'head_1> FnOnce(RentMut_BorrowMut<'head_0, 'head_1, T, U>) -> &'head_1 mut V,
__Fsuffix: for<'head_0, 'head_1> FnOnce(RentMut_BorrowMut<'head_0, 'head_1, T, U>) -> &'head_1 mut V,
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.
fn try_new<__Fsuffix, __E>(
head: Box<RentMut<T, U>>,
suffix: __Fsuffix
) -> TryNewResult<Self, __E, Box<RentMut<T, U>>> where
__Fsuffix: for<'head_0, 'head_1> FnOnce(RentMut_BorrowMut<'head_0, 'head_1, T, U>) -> Result<&'head_1 mut V, __E>,
head: Box<RentMut<T, U>>,
suffix: __Fsuffix
) -> TryNewResult<Self, __E, Box<RentMut<T, U>>> where
__Fsuffix: for<'head_0, 'head_1> FnOnce(RentMut_BorrowMut<'head_0, 'head_1, T, U>) -> Result<&'head_1 mut V, __E>,
Attempt to create a new instance of the rental struct.
As new
, but each closure returns a Result
. If the result is an error, execution is short-circuited and the error is returned to you, along with the original head value.
unsafe fn borrow<'__a>(&'__a self) -> Self::Borrow
Return direct shared borrows of the fields of the struct.
This is unsafe because the erased lifetimes are exposed. Use this only if absolutely necessary and be very mindful of what the true lifetimes are.
unsafe fn borrow_mut<'__a>(&'__a mut self) -> Self::BorrowMut
Return a direct mutable borrow of the suffix of the struct.
This is unsafe because the erased lifetimes are exposed. Use this only if absolutely necessary and be very mindful of what the true lifetimes are.
fn rent<__F, __R>(&self, f: __F) -> __R where
__F: for<'suffix, 'head_1> FnOnce(&'suffix &'head_1 mut V) -> __R,
__R: ,
__F: for<'suffix, 'head_1> FnOnce(&'suffix &'head_1 mut V) -> __R,
__R: ,
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.
fn rent_mut<__F, __R>(&mut self, f: __F) -> __R where
__F: for<'suffix, 'head_1> FnOnce(&'suffix mut &'head_1 mut V) -> __R,
__R: ,
__F: for<'suffix, 'head_1> FnOnce(&'suffix mut &'head_1 mut V) -> __R,
__R: ,
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.
fn ref_rent<__F, __R: ?Sized>(&self, f: __F) -> &__R where
__F: for<'suffix, 'head_1> FnOnce(&'suffix &'head_1 mut V) -> &'suffix __R,
__R: 'static,
__F: for<'suffix, 'head_1> FnOnce(&'suffix &'head_1 mut V) -> &'suffix __R,
__R: 'static,
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.
fn ref_rent_mut<__F, __R: ?Sized>(&mut self, f: __F) -> &mut __R where
__F: for<'suffix, 'head_1> FnOnce(&'suffix mut &'head_1 mut V) -> &'suffix mut __R,
__R: 'static,
__F: for<'suffix, 'head_1> FnOnce(&'suffix mut &'head_1 mut V) -> &'suffix mut __R,
__R: 'static,
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.
fn into_head(self) -> Box<RentMut<T, U>>
Drop the rental struct and return the original head value to you.
Trait Implementations
impl<T: 'static, U: 'static, V: 'static> Drop for RentMutMap<T, U, V>
[src]
impl<T: 'static, U: 'static, V: 'static> Deref for RentMutMap<T, U, V>
[src]
type Target = &'static mut V::Target
The resulting type after dereferencing
fn deref(&self) -> &Self::Target
The method called to dereference a value