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>
impl<T> Promise<T>
Sourcepub fn set_value(self, value: T) -> Option<T>
pub fn set_value(self, value: T) -> Option<T>
Offers a value to the promise.
It will wake up any awaited futures.
Sourcepub fn into_raw(s: Promise<T>) -> NonNull<MaybeUninit<T>>
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.
Sourcepub unsafe fn from_raw(ptr: NonNull<MaybeUninit<T>>) -> Promise<T>
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.
Sourcepub unsafe fn assume_value_set(self)
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§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more