Struct Lease

Source
pub struct Lease<T> { /* private fields */ }
Expand description

A handle to a leasable value.

Use poll_acquire to acquire the lease, take to grab the leased value, and restore to return the leased value when you’re done with it.

The code will panic if you attempt to access the S behind a Lease through Deref or DerefMut without having acquired the lease through poll_acquire first, or if you have called take.

The code will also panic if you attempt to drop a Lease without first restoring the leased value.

Implementations§

Source§

impl<T> Lease<T>

Source

pub fn poll_acquire(&mut self) -> Async<()>

Try to acquire the lease.

If the lease is not available, the current task is notified once it is.

Source

pub fn release(&mut self)

Release the lease (if it has been acquired).

This provides a way of “undoing” a call to poll_ready should you decide you don’t need the lease after all, or if you only needed access by reference.

This method will panic if you attempt to release the lease after you have called take.

Source

pub fn transfer(&mut self) -> Self

Leave behind a non-acquired lease in place of this one, and return this acquired lease.

This allows you to move a previously acquired lease into another context (like a Future) where you will later restore the leased value.

This method will panic if you attempt to call it without first having acquired the lease.

Source

pub fn take(&mut self) -> T

Take the leased value.

This method will panic if you attempt to call it without first having acquired the lease.

Note that you must call restore on this lease before you drop it to return the leased value to other waiting clients. If you do not, dropping the lease will panic.

Source

pub fn restore(&mut self, state: T)

Restore the leased value.

This method will panic if you attempt to call it without first having acquired the lease.

Note that once you return the leased value, the lease is no longer considered acquired.

Trait Implementations§

Source§

impl<T> Clone for Lease<T>

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for Lease<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Default for Lease<T>
where T: Default,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T> Deref for Lease<T>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<T> DerefMut for Lease<T>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<T> Drop for Lease<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T> From<T> for Lease<T>

Source§

fn from(s: T) -> Self

Converts to this type from the input type.
Source§

impl<T> Send for Lease<T>
where T: Send,

Auto Trait Implementations§

§

impl<T> Freeze for Lease<T>

§

impl<T> !RefUnwindSafe for Lease<T>

§

impl<T> !Sync for Lease<T>

§

impl<T> Unpin for Lease<T>

§

impl<T> !UnwindSafe for Lease<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.