Struct rental::RentRef
[−]
[src]
pub struct RentRef<'rental, T: FixedDeref + 'rental, B: ?Sized + 'rental> where T: FixedDeref { /* fields omitted */ }
A struct representing a particular (owner, rental) pair.
All such structs share a common API, but it is merely a convention
enforced by the rental
macro. The
capabilities of a rental struct cannot be fully described as a trait
without language support for HKT (Higher-Kinded Types). What methods
can be expressed in a trait are documented in the
Rental
and
RentalMut
traits.
A rental struct can implement Deref
, but only if the rented type
is Deref
and its target does not contain the 'rental
lifetime
in its signature.
Methods
impl<'rental, T: FixedDeref + 'rental, B: ?Sized + 'rental> RentRef<'rental, T, B> where T: FixedDeref
[src]
fn new<F__>(owner: T, f: F__) -> RentRef<'rental, T, B> where F__: for<'a__> FnOnce(&'a__ T::Target) -> &'a__ B
Instantiate a new shared rental pair. owner
is the object
from which a value will be rented. The closure takes a
reborrowed shared reference to the owner's Deref
target, and
returns the rented value. Within this closure, the special
'rental
lifetime is "existential" and cannot be unified with
any external lifetime. This is crucial in that it prevents any
borrow of the owner from escaping from the closure other than as
a return value.
fn try_new<E__, F__>(owner: T,
f: F__)
-> Result<RentRef<'rental, T, B>, (E__, T)> where F__: for<'a__> FnOnce(&'a__ T::Target) -> Result<&'a__ B, E__>
f: F__)
-> Result<RentRef<'rental, T, B>, (E__, T)> where F__: for<'a__> FnOnce(&'a__ T::Target) -> Result<&'a__ B, E__>
As new
, but the closure returns a Result
with a generic error. In the event of such failure, this method
will return Err
with a tuple of the error itself and the
owner object.
fn owner(&self) -> &T
Borrows the owner.
fn rent<'s__, F__, R__>(&'s__ self, f: F__) -> R__ where F__: for<'a__: 's__> FnOnce(&'s__ &'a__ B) -> R__, R__: 's__
Executes a closure on the existentially borrowed rental. The
closure may return anything, including a borrow, as long as the
existential 'rental
lifetime does not appear in the type
signature.
Trait Implementations
impl<'rental, T: FixedDeref + 'rental, B: ?Sized + 'rental> Rental for RentRef<'rental, T, B> where T: FixedDeref
[src]
type Owner = T
type Rental = &'rental B
unsafe fn rental(&self) -> &&'rental B
This returns to you the rented value outside of an existential closure. This is unsafe because the lifetime substituted for 'rental
here is a lie and does not reflect the true lifetime of the value. Only use this if you have no alternative, and think very carefully about how you're using the value to prevent it from outliving the rental struct, or inserting into it data that will not live long enough. Read more
fn from_parts(owner: T, rent: &'rental B) -> Self
This will produce a rental struct from component parts. Not unsafe because, if you already have the components safely, combining them in this way does not introduce any additional unsafety. Read more
unsafe fn into_parts(self) -> (T, &'rental B)
This will decompose a rental struct into its component parts. This is obviously unsafe because one may drop the owner while retaining the borrow. Read more
fn into_owner(self) -> T
This sill consume a rental struct and return to you the owner, discarding the rented value. Read more
impl<'rental, T: FixedDeref + 'rental, B: ?Sized + 'rental> Deref for RentRef<'rental, T, B> where T: FixedDeref, RentRef<'rental, T, B>::Rental: Deref<Target=B>
[src]
type Target = RentRef<'rental, T, B>::Rental::Target
The resulting type after dereferencing
fn deref(&self) -> &RentRef<'rental, T, B>::Rental::Target
The method called to dereference a value