Struct Promise

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

A struct that accepts a value and notify the corresponding future.

Implementations§

Source§

impl<T> Promise<T>

Source

pub fn set_value(self, value: T) -> Option<T>

Offers a value to the promise.

It will wake up any awaited futures.

Source

pub fn into_raw(s: Promise<T>) -> NonNull<MaybeUninit<T>>

Get a mutable pointer to the underlying value.

Remember to use from_raw to reclaim the memory and make notification work correctly.

Source

pub unsafe fn from_raw(ptr: NonNull<MaybeUninit<T>>) -> Promise<T>

Reconstruct the promise from given pointer.

The pointer must be the returned value of into_raw.

§Safety

If the pointer is not generated by into_raw, it can lead to undefined behavior.

Source

pub unsafe fn assume_value_set(self)

Assumes the value is set.

It will wake up any awaited futures.

§Safety

If no value has been set, calling the function lead to undefined behavior.

Trait Implementations§

Source§

impl<T> Drop for Promise<T>

Source§

fn drop(&mut self)

Drops the promise.

It will wake up any awaited futures.

Source§

impl<T: Send> Send for Promise<T>

Auto Trait Implementations§

§

impl<T> Freeze for Promise<T>

§

impl<T> !RefUnwindSafe for Promise<T>

§

impl<T> !Sync for Promise<T>

§

impl<T> Unpin for Promise<T>

§

impl<T> !UnwindSafe for Promise<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> 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<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.