Struct rental::examples::RentRefMap
[−]
[src]
pub struct RentRefMap<T: 'static, U: 'static, V: 'static> { /* fields omitted */ }
An example that borrows off of another rental struct.
let r = RentRef::new(Box::new(5), |i| &*i); let rm = RentRefMap::new(Box::new(r), |r| &**r.suffix); assert_eq!(*rm, rm.rent(|iref| **iref));
Methods
impl<T: 'static, U: 'static, V: 'static> RentRefMap<T, U, V>
[src]
fn new<__Fsuffix>(head: Box<RentRef<T, U>>, suffix: __Fsuffix) -> Self where
__Fsuffix: for<'head_0, 'head_1> FnOnce(RentRef_Borrow<'head_0, 'head_1, T, U>) -> &'head_1 V,
[src]
__Fsuffix: for<'head_0, 'head_1> FnOnce(RentRef_Borrow<'head_0, 'head_1, T, U>) -> &'head_1 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<RentRef<T, U>>,
suffix: __Fsuffix
) -> TryNewResult<Self, __E, Box<RentRef<T, U>>> where
__Fsuffix: for<'head_0, 'head_1> FnOnce(RentRef_Borrow<'head_0, 'head_1, T, U>) -> Result<&'head_1 V, __E>,
[src]
head: Box<RentRef<T, U>>,
suffix: __Fsuffix
) -> TryNewResult<Self, __E, Box<RentRef<T, U>>> where
__Fsuffix: for<'head_0, 'head_1> FnOnce(RentRef_Borrow<'head_0, 'head_1, T, U>) -> Result<&'head_1 V, __E>,
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.
fn try_new_or_drop<__Fsuffix, __E>(
head: Box<RentRef<T, U>>,
suffix: __Fsuffix
) -> Result<Self, __E> where
__Fsuffix: for<'head_0, 'head_1> FnOnce(RentRef_Borrow<'head_0, 'head_1, T, U>) -> Result<&'head_1 V, __E>,
[src]
head: Box<RentRef<T, U>>,
suffix: __Fsuffix
) -> Result<Self, __E> where
__Fsuffix: for<'head_0, 'head_1> FnOnce(RentRef_Borrow<'head_0, 'head_1, T, U>) -> Result<&'head_1 V, __E>,
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.
unsafe fn borrow<'__a>(&'__a self) -> Self::Borrow
[src]
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
[src]
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 V) -> __R,
__R: ,
[src]
__F: for<'suffix, 'head_1> FnOnce(&'suffix &'head_1 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 V) -> __R,
__R: ,
[src]
__F: for<'suffix, 'head_1> FnOnce(&'suffix mut &'head_1 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 V) -> &'suffix __R,
__R: 'static,
[src]
__F: for<'suffix, 'head_1> FnOnce(&'suffix &'head_1 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 maybe_ref_rent<__F, __R: ?Sized>(&self, f: __F) -> Option<&__R> where
__F: for<'suffix, 'head_1> FnOnce(&'suffix &'head_1 V) -> Option<&'suffix __R>,
__R: 'static,
[src]
__F: for<'suffix, 'head_1> FnOnce(&'suffix &'head_1 V) -> 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_1> FnOnce(&'suffix &'head_1 V) -> Result<&'suffix __R, __E>,
__R: 'static,
[src]
__F: for<'suffix, 'head_1> FnOnce(&'suffix &'head_1 V) -> 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_1> FnOnce(&'suffix mut &'head_1 V) -> &'suffix mut __R,
__R: 'static,
[src]
__F: for<'suffix, 'head_1> FnOnce(&'suffix mut &'head_1 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 maybe_ref_rent_mut<__F, __R: ?Sized>(&mut self, f: __F) -> Option<&mut __R> where
__F: for<'suffix, 'head_1> FnOnce(&'suffix mut &'head_1 V) -> Option<&'suffix mut __R>,
__R: 'static,
[src]
__F: for<'suffix, 'head_1> FnOnce(&'suffix mut &'head_1 V) -> 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_1> FnOnce(&'suffix mut &'head_1 V) -> Result<&'suffix mut __R, __E>,
__R: 'static,
[src]
&mut self,
f: __F
) -> Result<&mut __R, __E> where
__F: for<'suffix, 'head_1> FnOnce(&'suffix mut &'head_1 V) -> 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<RentRef<T, U>>
[src]
Drop the rental struct and return the original head value to you.
impl<T: 'static, U: 'static, V: 'static> RentRefMap<T, U, V>
[src]
fn head(&self) -> &<Box<RentRef<T, U>> as Deref>::Target
[src]
Return a shared reference to the head field of the struct.
fn rent_all<__F, __R>(&self, f: __F) -> __R where
__F: for<'head_0, 'head_1, 'suffix> FnOnce(RentRefMap_Borrow<'head_0, 'head_1, 'suffix, T, U, V>) -> __R,
__R: ,
[src]
__F: for<'head_0, 'head_1, 'suffix> FnOnce(RentRefMap_Borrow<'head_0, 'head_1, 'suffix, T, U, V>) -> __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_0, 'head_1, 'suffix> FnOnce(RentRefMap_Borrow<'head_0, 'head_1, 'suffix, T, U, V>) -> &'suffix __R,
__R: 'static,
[src]
__F: for<'head_0, 'head_1, 'suffix> FnOnce(RentRefMap_Borrow<'head_0, 'head_1, 'suffix, T, U, V>) -> &'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 maybe_ref_rent_all<__F, __R: ?Sized>(&self, f: __F) -> Option<&__R> where
__F: for<'head_0, 'head_1, 'suffix> FnOnce(RentRefMap_Borrow<'head_0, 'head_1, 'suffix, T, U, V>) -> Option<&'suffix __R>,
__R: 'static,
[src]
__F: for<'head_0, 'head_1, 'suffix> FnOnce(RentRefMap_Borrow<'head_0, 'head_1, 'suffix, T, U, V>) -> Option<&'suffix __R>,
__R: 'static,
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.
fn try_ref_rent_all<__F, __R: ?Sized, __E>(&self, f: __F) -> Result<&__R, __E> where
__F: for<'head_0, 'head_1, 'suffix> FnOnce(RentRefMap_Borrow<'head_0, 'head_1, 'suffix, T, U, V>) -> Result<&'suffix __R, __E>,
__R: 'static,
[src]
__F: for<'head_0, 'head_1, 'suffix> FnOnce(RentRefMap_Borrow<'head_0, 'head_1, 'suffix, T, U, V>) -> Result<&'suffix __R, __E>,
__R: 'static,
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.
fn rent_all_mut<__F, __R>(&mut self, f: __F) -> __R where
__F: for<'head_0, 'head_1, 'suffix> FnOnce(RentRefMap_BorrowMut<'head_0, 'head_1, 'suffix, T, U, V>) -> __R,
__R: ,
[src]
__F: for<'head_0, 'head_1, 'suffix> FnOnce(RentRefMap_BorrowMut<'head_0, 'head_1, 'suffix, T, U, V>) -> __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) -> &mut __R where
__F: for<'head_0, 'head_1, 'suffix> FnOnce(RentRefMap_BorrowMut<'head_0, 'head_1, 'suffix, T, U, V>) -> &'suffix mut __R,
__R: 'static,
[src]
__F: for<'head_0, 'head_1, 'suffix> FnOnce(RentRefMap_BorrowMut<'head_0, 'head_1, 'suffix, T, U, V>) -> &'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.
fn maybe_ref_rent_all_mut<__F, __R: ?Sized>(
&mut self,
f: __F
) -> Option<&mut __R> where
__F: for<'head_0, 'head_1, 'suffix> FnOnce(RentRefMap_BorrowMut<'head_0, 'head_1, 'suffix, T, U, V>) -> Option<&'suffix mut __R>,
__R: 'static,
[src]
&mut self,
f: __F
) -> Option<&mut __R> where
__F: for<'head_0, 'head_1, 'suffix> FnOnce(RentRefMap_BorrowMut<'head_0, 'head_1, 'suffix, T, U, V>) -> Option<&'suffix mut __R>,
__R: 'static,
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.
fn try_ref_rent_all_mut<__F, __R: ?Sized, __E>(
&mut self,
f: __F
) -> Result<&mut __R, __E> where
__F: for<'head_0, 'head_1, 'suffix> FnOnce(RentRefMap_BorrowMut<'head_0, 'head_1, 'suffix, T, U, V>) -> Result<&'suffix mut __R, __E>,
__R: 'static,
[src]
&mut self,
f: __F
) -> Result<&mut __R, __E> where
__F: for<'head_0, 'head_1, 'suffix> FnOnce(RentRefMap_BorrowMut<'head_0, 'head_1, 'suffix, T, U, V>) -> Result<&'suffix mut __R, __E>,
__R: 'static,
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.
Trait Implementations
impl<T: 'static, U: 'static, V: 'static> Deref for RentRefMap<T, U, V>
[src]
type Target = <&'static V as Deref>::Target
The resulting type after dereferencing.
fn deref(&self) -> &Self::Target
[src]
Dereferences the value.