[][src]Struct tiny_future::Future

pub struct Future<T, U = ()>(_);

A future result with an optional shared state

Implementations

impl<T, U> Future<T, U>[src]

pub fn with_state(shared_state: U) -> Self[src]

Creates a new Future<T, U> with shared_state as shared-state

pub fn set(&self, result: T) -> Result<(), State>[src]

Sets the future

pub fn cancel(&self)[src]

Cancels (poisons) the future

This is useful to indicate that the future is obsolete and should not be set anymore

pub fn get_state(&self) -> State[src]

Returns the future's state

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

Checks if the future is still waiting or has been set/canceled

pub fn try_get(&self) -> Result<T, State>[src]

Tries to get the future's result

If the future is ready, it is consumed and T is returned; if the future is not ready, Error::InvalidState(State) is returned

pub fn try_get_timeout(&self, timeout: Duration) -> Result<T, State>[src]

Tries to get the future's result

If the future is ready or or becomes ready before the timeout occurres, it is consumed and T is returned; if the future is not ready, Error::InvalidState(State) is returned

pub fn get(&self) -> Result<T, State>[src]

Gets the future's result

Warning: this function will block until a result becomes available

pub fn get_shared_state(&self) -> U where
    U: Clone
[src]

Get a clone of the current shared state

pub fn set_shared_state(&self, shared_state: U)[src]

Replace the current shared state

pub fn access_shared_state<F: FnOnce(&mut U)>(&self, modifier: F)[src]

Provides exclusive access to the shared state within modifier until modifier returns

pub fn access_shared_state_param<V, F: FnOnce(&mut U, V)>(
    &self,
    modifier: F,
    parameter: V
)
[src]

Provides exclusive access to the shared state within modifier until modifier returns

pub fn detach(&self)[src]

Detaches the future so it won't be canceled if there is only one instance left

Useful if you either don't want that your future is ever canceled or if there's always only one instance (e.g. if you wrap it into a reference-counting container)

impl<T> Future<T, ()>[src]

pub fn new() -> Self[src]

Trait Implementations

impl<T, U> Clone for Future<T, U>[src]

impl<T, U> Default for Future<T, U> where
    U: Default
[src]

impl<T, U> Drop for Future<T, U>[src]

impl<T: Send, U: Send> Send for Future<T, U>[src]

impl<T, U> Sync for Future<T, U>[src]

Auto Trait Implementations

impl<T, U = ()> !RefUnwindSafe for Future<T, U>

impl<T, U> Unpin for Future<T, U>

impl<T, U = ()> !UnwindSafe for Future<T, U>

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> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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.