[][src]Struct potential::Potential

pub struct Potential<T> { /* fields omitted */ }

The owner of an item leases it out or can access mutably if not leased.

Implementations

impl<T> Potential<T>[src]

pub fn new(item: T) -> Self[src]

Create new full Potential

pub fn empty() -> Self[src]

Create new empty Potential

pub fn is_leased(&self) -> bool[src]

Check if the item is waiting for return of the lease right now

pub fn is_present(&self) -> bool[src]

Check if the item is present right now

pub fn is_empty(&self) -> bool[src]

Check if the item is gone right now

pub fn set(&mut self, item: T)[src]

Set the current item immediately regardles of lease. Sucessful lease will not return their item on drop. Pending and subsequent leases will pick the new value.

let mut potential = Potential::new("x");
potential.set("y");

To set through an immutable reference, feed it back through a lease. Call:

potential.lease().await?.replace(value);

pub async fn reset<'_>(&'_ self) -> Gone<T>[src]

pub async fn lease_on_arc(self: Arc<Self>) -> Result<Lease<T>, Gone<T>>[src]

Sync + Send + 'static flavor of lease() if Self is in Arc

pub async fn lease_on_rc(self: Rc<Self>) -> Result<Lease<T>, Gone<T>>[src]

'static flavor of lease() if Self is in Rc

pub async fn get_mut<'_, '_>(&'_ mut self) -> Option<&'_ mut T>[src]

Wait for the item to be available and then access the mutable reference if available. This call will return None if previous Lease failed to return the item or if created empty(). If that happens, set a new potential.

Example:

let mut potential = Potential::new(String::new());
potential.get_mut().await?.push('A');

pub async fn lease<'_>(&'_ self) -> Result<Lease<T>, Gone<T>>[src]

Wait for the return of the item and if available, lease it. This call will return Err(Gone) if previous Lease failed to return the item or if created empty(). If that happens, set a new potential on the Gone.

Example:

let mut potential = Potential::new(String::new());
potential.lease().await?.push('A');

Example of empty potential:

let mut potential = Potential::empty();
let mut lease = match potential.lease().await {
    Err(gone) => gone.set(String::new()),
    Ok(lease) => lease
};
lease.push('A');

Trait Implementations

impl<T: Debug> Debug for Potential<T>[src]

impl<T: Default> Default for Potential<T>[src]

Auto Trait Implementations

impl<T> !RefUnwindSafe for Potential<T>

impl<T> Send for Potential<T> where
    T: Send

impl<T> Sync for Potential<T> where
    T: Send

impl<T> Unpin for Potential<T> where
    T: Unpin

impl<T> !UnwindSafe for Potential<T>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.