Struct rental::examples::RentMut
[−]
[src]
pub struct RentMut<T: 'static, U: 'static> { /* fields omitted */ }
A simple example that can store 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, r.rent(|iref| **iref));
Methods
impl<T: 'static, U: 'static> RentMut<T, U>
[src]
fn new<__Fsuffix>(head: Box<T>, suffix: __Fsuffix) -> Self where
__Fsuffix: for<'head> FnOnce(&'head mut T) -> &'head mut U,
__Fsuffix: for<'head> FnOnce(&'head mut T) -> &'head mut U,
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<T>,
suffix: __Fsuffix
) -> TryNewResult<Self, __E, Box<T>> where
__Fsuffix: for<'head> FnOnce(&'head mut T) -> Result<&'head mut U, __E>,
head: Box<T>,
suffix: __Fsuffix
) -> TryNewResult<Self, __E, Box<T>> where
__Fsuffix: for<'head> FnOnce(&'head mut T) -> Result<&'head mut U, __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> FnOnce(&'suffix &'head mut U) -> __R,
__R: ,
__F: for<'suffix, 'head> FnOnce(&'suffix &'head mut U) -> __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> FnOnce(&'suffix mut &'head mut U) -> __R,
__R: ,
__F: for<'suffix, 'head> FnOnce(&'suffix mut &'head mut U) -> __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> FnOnce(&'suffix &'head mut U) -> &'suffix __R,
__R: 'static,
__F: for<'suffix, 'head> FnOnce(&'suffix &'head mut U) -> &'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 maybe_ref_rent<__F, __R: ?Sized>(&self, f: __F) -> Option<&__R> where
__F: for<'suffix, 'head> FnOnce(&'suffix &'head mut U) -> Option<&'suffix __R>,
__R: 'static,
__F: for<'suffix, 'head> FnOnce(&'suffix &'head mut U) -> Option<&'suffix __R>,
__R: 'static,
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.
fn try_ref_rent<__F, __R: ?Sized, __E>(&self, f: __F) -> Result<&__R, __E> where
__F: for<'suffix, 'head> FnOnce(&'suffix &'head mut U) -> Result<&'suffix __R, __E>,
__R: 'static,
__F: for<'suffix, 'head> FnOnce(&'suffix &'head mut U) -> Result<&'suffix __R, __E>,
__R: 'static,
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.
fn ref_rent_mut<__F, __R: ?Sized>(&mut self, f: __F) -> &mut __R where
__F: for<'suffix, 'head> FnOnce(&'suffix mut &'head mut U) -> &'suffix mut __R,
__R: 'static,
__F: for<'suffix, 'head> FnOnce(&'suffix mut &'head mut U) -> &'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 maybe_ref_rent_mut<__F, __R: ?Sized>(&mut self, f: __F) -> Option<&mut __R> where
__F: for<'suffix, 'head> FnOnce(&'suffix mut &'head mut U) -> Option<&'suffix mut __R>,
__R: 'static,
__F: for<'suffix, 'head> FnOnce(&'suffix mut &'head mut U) -> Option<&'suffix mut __R>,
__R: 'static,
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.
fn try_ref_rent_mut<__F, __R: ?Sized, __E>(
&mut self,
f: __F
) -> Result<&mut __R, __E> where
__F: for<'suffix, 'head> FnOnce(&'suffix mut &'head mut U) -> Result<&'suffix mut __R, __E>,
__R: 'static,
&mut self,
f: __F
) -> Result<&mut __R, __E> where
__F: for<'suffix, 'head> FnOnce(&'suffix mut &'head mut U) -> Result<&'suffix mut __R, __E>,
__R: 'static,
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.
fn into_head(self) -> Box<T>
Drop the rental struct and return the original head value to you.
Trait Implementations
impl<T: 'static, U: 'static> Deref for RentMut<T, U>
[src]
type Target = <&'static mut U as Deref>::Target
The resulting type after dereferencing
fn deref(&self) -> &Self::Target
The method called to dereference a value