[−][src]Struct rental::common::RentMutex
Stores a Mutex
and a MutexGuard
in the same struct.
use std::sync; let mut r = RentMutex::new(Box::new(sync::Mutex::new(5)), |c| c.lock().unwrap()); *r = 12; assert_eq!(12, RentMutex::rent(&r, |c| **c));
Implementations
impl<H: 'static + StableDeref + DerefMut, T: 'static> RentMutex<H, T>
[src]
pub fn new<__Fsuffix>(head: H, suffix: __Fsuffix) -> Self where
__Fsuffix: for<'head> FnOnce(&'head <H as Deref>::Target) -> MutexGuard<'head, T>,
[src]
__Fsuffix: for<'head> FnOnce(&'head <H as Deref>::Target) -> MutexGuard<'head, T>,
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.
pub fn try_new<__Fsuffix, __E>(
head: H,
suffix: __Fsuffix
) -> RentalResult<Self, __E, H> where
__Fsuffix: for<'head> FnOnce(&'head <H as Deref>::Target) -> Result<MutexGuard<'head, T>, __E>,
[src]
head: H,
suffix: __Fsuffix
) -> RentalResult<Self, __E, H> where
__Fsuffix: for<'head> FnOnce(&'head <H as Deref>::Target) -> Result<MutexGuard<'head, T>, __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.
pub fn try_new_or_drop<__Fsuffix, __E>(
head: H,
suffix: __Fsuffix
) -> Result<Self, __E> where
__Fsuffix: for<'head> FnOnce(&'head <H as Deref>::Target) -> Result<MutexGuard<'head, T>, __E>,
[src]
head: H,
suffix: __Fsuffix
) -> Result<Self, __E> where
__Fsuffix: for<'head> FnOnce(&'head <H as Deref>::Target) -> Result<MutexGuard<'head, T>, __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.
pub unsafe fn all_erased(_self: &Self) -> Self::Borrow
[src]
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.
pub unsafe fn all_mut_erased(_self: &mut Self) -> Self::BorrowMut
[src]
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.
pub fn rent<__F, __R>(_self: &Self, f: __F) -> __R where
__F: for<'suffix, 'head> FnOnce(&'suffix MutexGuard<'head, T>) -> __R,
__R: ,
[src]
__F: for<'suffix, 'head> FnOnce(&'suffix MutexGuard<'head, T>) -> __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 rental lifetimes of the struct.
pub fn rent_mut<__F, __R>(_self: &mut Self, f: __F) -> __R where
__F: for<'suffix, 'head> FnOnce(&'suffix mut MutexGuard<'head, T>) -> __R,
__R: ,
[src]
__F: for<'suffix, 'head> FnOnce(&'suffix mut MutexGuard<'head, T>) -> __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 rental lifetimes of the struct.
pub fn ref_rent<__F, __R>(_self: &Self, f: __F) -> &__R where
__F: for<'suffix, 'head> FnOnce(&'suffix MutexGuard<'head, T>) -> &'suffix __R,
__R: ?Sized,
[src]
__F: for<'suffix, 'head> FnOnce(&'suffix MutexGuard<'head, T>) -> &'suffix __R,
__R: ?Sized,
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.
pub fn maybe_ref_rent<__F, __R>(_self: &Self, f: __F) -> Option<&__R> where
__F: for<'suffix, 'head> FnOnce(&'suffix MutexGuard<'head, T>) -> Option<&'suffix __R>,
__R: ?Sized,
[src]
__F: for<'suffix, 'head> FnOnce(&'suffix MutexGuard<'head, T>) -> Option<&'suffix __R>,
__R: ?Sized,
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.
pub fn try_ref_rent<__F, __R, __E>(_self: &Self, f: __F) -> Result<&__R, __E> where
__F: for<'suffix, 'head> FnOnce(&'suffix MutexGuard<'head, T>) -> Result<&'suffix __R, __E>,
__R: ?Sized,
[src]
__F: for<'suffix, 'head> FnOnce(&'suffix MutexGuard<'head, T>) -> Result<&'suffix __R, __E>,
__R: ?Sized,
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.
pub fn ref_rent_mut<__F, __R>(_self: &mut Self, f: __F) -> &mut __R where
__F: for<'suffix, 'head> FnOnce(&'suffix mut MutexGuard<'head, T>) -> &'suffix mut __R,
__R: ?Sized,
[src]
__F: for<'suffix, 'head> FnOnce(&'suffix mut MutexGuard<'head, T>) -> &'suffix mut __R,
__R: ?Sized,
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.
pub fn maybe_ref_rent_mut<__F, __R>(
_self: &mut Self,
f: __F
) -> Option<&mut __R> where
__F: for<'suffix, 'head> FnOnce(&'suffix mut MutexGuard<'head, T>) -> Option<&'suffix mut __R>,
__R: ?Sized,
[src]
_self: &mut Self,
f: __F
) -> Option<&mut __R> where
__F: for<'suffix, 'head> FnOnce(&'suffix mut MutexGuard<'head, T>) -> Option<&'suffix mut __R>,
__R: ?Sized,
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.
pub fn try_ref_rent_mut<__F, __R, __E>(
_self: &mut Self,
f: __F
) -> Result<&mut __R, __E> where
__F: for<'suffix, 'head> FnOnce(&'suffix mut MutexGuard<'head, T>) -> Result<&'suffix mut __R, __E>,
__R: ?Sized,
[src]
_self: &mut Self,
f: __F
) -> Result<&mut __R, __E> where
__F: for<'suffix, 'head> FnOnce(&'suffix mut MutexGuard<'head, T>) -> Result<&'suffix mut __R, __E>,
__R: ?Sized,
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.
pub fn into_head(_self: Self) -> H
[src]
Drop the rental struct and return the original head value to you.
impl<H: 'static + StableDeref + DerefMut, T: 'static> RentMutex<H, T>
[src]
pub fn head(_self: &Self) -> &<H as Deref>::Target
[src]
Return a shared reference to the head field of the struct.
pub fn rent_all<__F, __R>(_self: &Self, f: __F) -> __R where
__F: for<'head, 'suffix> FnOnce(RentMutex_Borrow<'head, 'suffix, H, T>) -> __R,
__R: ,
[src]
__F: for<'head, 'suffix> FnOnce(RentMutex_Borrow<'head, 'suffix, H, T>) -> __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 rental lifetimes of the struct.
pub fn ref_rent_all<__F, __R>(_self: &Self, f: __F) -> &__R where
__F: for<'head, 'suffix> FnOnce(RentMutex_Borrow<'head, 'suffix, H, T>) -> &'suffix __R,
__R: ?Sized,
[src]
__F: for<'head, 'suffix> FnOnce(RentMutex_Borrow<'head, 'suffix, H, T>) -> &'suffix __R,
__R: ?Sized,
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.
pub fn maybe_ref_rent_all<__F, __R>(_self: &Self, f: __F) -> Option<&__R> where
__F: for<'head, 'suffix> FnOnce(RentMutex_Borrow<'head, 'suffix, H, T>) -> Option<&'suffix __R>,
__R: ?Sized,
[src]
__F: for<'head, 'suffix> FnOnce(RentMutex_Borrow<'head, 'suffix, H, T>) -> Option<&'suffix __R>,
__R: ?Sized,
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.
pub fn try_ref_rent_all<__F, __R, __E>(
_self: &Self,
f: __F
) -> Result<&__R, __E> where
__F: for<'head, 'suffix> FnOnce(RentMutex_Borrow<'head, 'suffix, H, T>) -> Result<&'suffix __R, __E>,
__R: ?Sized,
[src]
_self: &Self,
f: __F
) -> Result<&__R, __E> where
__F: for<'head, 'suffix> FnOnce(RentMutex_Borrow<'head, 'suffix, H, T>) -> Result<&'suffix __R, __E>,
__R: ?Sized,
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.
pub fn rent_all_mut<__F, __R>(_self: &mut Self, f: __F) -> __R where
__F: for<'head, 'suffix> FnOnce(RentMutex_BorrowMut<'head, 'suffix, H, T>) -> __R,
__R: ,
[src]
__F: for<'head, 'suffix> FnOnce(RentMutex_BorrowMut<'head, 'suffix, H, T>) -> __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 rental lifetimes of the struct.
pub fn ref_rent_all_mut<__F, __R>(_self: &mut Self, f: __F) -> &mut __R where
__F: for<'head, 'suffix> FnOnce(RentMutex_BorrowMut<'head, 'suffix, H, T>) -> &'suffix mut __R,
__R: ?Sized,
[src]
__F: for<'head, 'suffix> FnOnce(RentMutex_BorrowMut<'head, 'suffix, H, T>) -> &'suffix mut __R,
__R: ?Sized,
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.
pub fn maybe_ref_rent_all_mut<__F, __R>(
_self: &mut Self,
f: __F
) -> Option<&mut __R> where
__F: for<'head, 'suffix> FnOnce(RentMutex_BorrowMut<'head, 'suffix, H, T>) -> Option<&'suffix mut __R>,
__R: ?Sized,
[src]
_self: &mut Self,
f: __F
) -> Option<&mut __R> where
__F: for<'head, 'suffix> FnOnce(RentMutex_BorrowMut<'head, 'suffix, H, T>) -> Option<&'suffix mut __R>,
__R: ?Sized,
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.
pub fn try_ref_rent_all_mut<__F, __R, __E>(
_self: &mut Self,
f: __F
) -> Result<&mut __R, __E> where
__F: for<'head, 'suffix> FnOnce(RentMutex_BorrowMut<'head, 'suffix, H, T>) -> Result<&'suffix mut __R, __E>,
__R: ?Sized,
[src]
_self: &mut Self,
f: __F
) -> Result<&mut __R, __E> where
__F: for<'head, 'suffix> FnOnce(RentMutex_BorrowMut<'head, 'suffix, H, T>) -> Result<&'suffix mut __R, __E>,
__R: ?Sized,
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 + DerefMut, T: 'static> RentMutex<H, T>
[src]
pub fn all<'__s>(_self: &'__s Self) -> Self::Borrow
[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.
pub fn suffix(_self: &Self) -> <Self::Borrow as IntoSuffix>::Suffix
[src]
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 + DerefMut, T: 'static> RentMutex<H, T>
[src]
pub fn map<__U: 'static, __F>(_self: Self, __f: __F) -> RentMutex<H, __U> where
__F: for<'suffix, 'head> FnOnce(MutexGuard<'head, T>) -> MutexGuard<'head, __U>,
[src]
__F: for<'suffix, 'head> FnOnce(MutexGuard<'head, T>) -> MutexGuard<'head, __U>,
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.
pub fn try_map<__U: 'static, __F, __E>(
_self: Self,
__f: __F
) -> RentalResult<RentMutex<H, __U>, __E, H> where
__F: for<'suffix, 'head> FnOnce(MutexGuard<'head, T>) -> Result<MutexGuard<'head, __U>, __E>,
[src]
_self: Self,
__f: __F
) -> RentalResult<RentMutex<H, __U>, __E, H> where
__F: for<'suffix, 'head> FnOnce(MutexGuard<'head, T>) -> Result<MutexGuard<'head, __U>, __E>,
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.
pub fn try_map_or_drop<__U: 'static, __F, __E>(
_self: Self,
__f: __F
) -> Result<RentMutex<H, __U>, __E> where
__F: for<'suffix, 'head> FnOnce(MutexGuard<'head, T>) -> Result<MutexGuard<'head, __U>, __E>,
[src]
_self: Self,
__f: __F
) -> Result<RentMutex<H, __U>, __E> where
__F: for<'suffix, 'head> FnOnce(MutexGuard<'head, T>) -> Result<MutexGuard<'head, __U>, __E>,
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 + DerefMut, T: 'static> AsMut<<RentMutex<H, T> as Deref>::Target> for RentMutex<H, T>
[src]
impl<H: 'static + StableDeref + DerefMut, T: 'static> AsRef<<RentMutex<H, T> as Deref>::Target> for RentMutex<H, T>
[src]
impl<H: 'static + StableDeref + DerefMut, T: 'static> Clone for RentMutex<H, T> where
H: CloneStableDeref,
MutexGuard<'static, T>: Clone,
[src]
H: CloneStableDeref,
MutexGuard<'static, T>: Clone,
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<H: 'static + StableDeref + DerefMut, T: 'static> Debug for RentMutex<H, T> where
H: Debug,
MutexGuard<'static, T>: Debug,
[src]
H: Debug,
MutexGuard<'static, T>: Debug,
impl<H: 'static + StableDeref + DerefMut, T: 'static> Deref for RentMutex<H, T>
[src]
type Target = <MutexGuard<'static, T> as Deref>::Target
The resulting type after dereferencing.
fn deref(&self) -> &Self::Target
[src]
impl<H: 'static + StableDeref + DerefMut, T: 'static> DerefMut for RentMutex<H, T>
[src]
Auto Trait Implementations
impl<H, T> RefUnwindSafe for RentMutex<H, T> where
H: RefUnwindSafe,
H: RefUnwindSafe,
impl<H, T> !Send for RentMutex<H, T>
impl<H, T> Sync for RentMutex<H, T> where
H: Sync,
T: Sync,
H: Sync,
T: Sync,
impl<H, T> Unpin for RentMutex<H, T> where
H: Unpin,
H: Unpin,
impl<H, T> UnwindSafe for RentMutex<H, T> where
H: UnwindSafe,
H: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,