[−][src]Struct potential::Potential
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
Auto Trait Implementations
impl<T> !RefUnwindSafe for Potential<T>
impl<T> Send for Potential<T> where
T: Send,
T: Send,
impl<T> Sync for Potential<T> where
T: Send,
T: Send,
impl<T> Unpin for Potential<T> where
T: Unpin,
T: Unpin,
impl<T> !UnwindSafe for Potential<T>
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>,