Struct rental::examples::RentRef
[−]
[src]
pub struct RentRef<T: 'static, U: 'static> { /* fields omitted */ }
A simple example that can store an owner and a shared reference in the same struct.
let r = RentRef::new(Box::new(5), |i| &*i); assert_eq!(*r, r.rent(|iref| **iref));
Methods
impl<T: 'static, U: 'static> RentRef<T, U>
[src]
fn new<__Fsuffix>(head: Box<T>, suffix: __Fsuffix) -> Self where
__Fsuffix: for<'head> FnOnce(&'head T) -> &'head U,
__Fsuffix: for<'head> FnOnce(&'head T) -> &'head 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 T) -> Result<&'head U, __E>,
head: Box<T>,
suffix: __Fsuffix
) -> TryNewResult<Self, __E, Box<T>> where
__Fsuffix: for<'head> FnOnce(&'head T) -> Result<&'head 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 U) -> __R,
__R: ,
__F: for<'suffix, 'head> FnOnce(&'suffix &'head 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 U) -> __R,
__R: ,
__F: for<'suffix, 'head> FnOnce(&'suffix mut &'head 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 U) -> &'suffix __R,
__R: 'static,
__F: for<'suffix, 'head> FnOnce(&'suffix &'head 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 ref_rent_mut<__F, __R: ?Sized>(&mut self, f: __F) -> &mut __R where
__F: for<'suffix, 'head> FnOnce(&'suffix mut &'head U) -> &'suffix mut __R,
__R: 'static,
__F: for<'suffix, 'head> FnOnce(&'suffix mut &'head 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 into_head(self) -> Box<T>
Drop the rental struct and return the original head value to you.
impl<T: 'static, U: 'static> RentRef<T, U>
[src]
fn head(&self) -> &<Box<T> as Deref>::Target
Return a shared reference to the head field of the struct.
fn rent_all<__F, __R>(&self, f: __F) -> __R where
__F: for<'head, 'suffix> FnOnce(RentRef_Borrow<'head, 'suffix, T, U>) -> __R,
__R: ,
__F: for<'head, 'suffix> FnOnce(RentRef_Borrow<'head, 'suffix, T, U>) -> __R,
__R: ,
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.
fn ref_rent_all<__F, __R: ?Sized>(&self, f: __F) -> &__R where
__F: for<'head, 'suffix> FnOnce(RentRef_Borrow<'head, 'suffix, T, U>) -> &'suffix __R,
__R: 'static,
__F: for<'head, 'suffix> FnOnce(RentRef_Borrow<'head, 'suffix, T, U>) -> &'suffix __R,
__R: 'static,
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.
fn rent_all_mut<__F, __R>(&mut self, f: __F) -> __R where
__F: for<'head, 'suffix> FnOnce(RentRef_BorrowMut<'head, 'suffix, T, U>) -> __R,
__R: ,
__F: for<'head, 'suffix> FnOnce(RentRef_BorrowMut<'head, 'suffix, T, U>) -> __R,
__R: ,
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.
fn ref_rent_all_mut<__F, __R: ?Sized>(&mut self, f: __F) -> &__R where
__F: for<'head, 'suffix> FnOnce(RentRef_BorrowMut<'head, 'suffix, T, U>) -> &'suffix mut __R,
__R: 'static,
__F: for<'head, 'suffix> FnOnce(RentRef_BorrowMut<'head, 'suffix, T, U>) -> &'suffix mut __R,
__R: 'static,
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.
Trait Implementations
impl<T: 'static, U: 'static> Drop for RentRef<T, U>
[src]
impl<T: 'static, U: 'static> Deref for RentRef<T, U>
[src]
type Target = <&'static U as Deref>::Target
The resulting type after dereferencing
fn deref(&self) -> &Self::Target
The method called to dereference a value