pub struct MaybePromise<'js>(/* private fields */);
Expand description
A type which behaves like a promise but can wrap any javascript value.
This type is usefull when you are unsure if a function will return a promise. You can call finish and turn it into a future like a normal promise. When the value this type us converted isn’t a promise it will behave like an promise which is already resolved, otherwise it will call the right functions on the promise.
Implementations§
Source§impl<'js> MaybePromise<'js>
impl<'js> MaybePromise<'js>
Sourcepub fn into_value(self) -> Value<'js>
pub fn into_value(self) -> Value<'js>
Convert into the inner value
Sourcepub fn from_value(value: Value<'js>) -> Self
pub fn from_value(value: Value<'js>) -> Self
Convert into the inner value
Sourcepub fn state(&self) -> PromiseState
pub fn state(&self) -> PromiseState
Returns PromiseState::Resolved
if the wrapped value isn’t a promise, otherwise calls
Promise::state
on the promise and returns it’s value.
Sourcepub fn result<T: FromJs<'js>>(&self) -> Option<Result<T>>
pub fn result<T: FromJs<'js>>(&self) -> Option<Result<T>>
Returns the value if self isn’t a promise, otherwise calls Promise::result
on the promise.
Sourcepub fn finish<T: FromJs<'js>>(&self) -> Result<T>
pub fn finish<T: FromJs<'js>>(&self) -> Result<T>
Returns the value if self isn’t a promise, otherwise calls Promise::finish
on the promise.
Sourcepub fn into_future<T: FromJs<'js>>(self) -> MaybePromiseFuture<'js, T> ⓘ
Available on crate feature futures
only.
pub fn into_future<T: FromJs<'js>>(self) -> MaybePromiseFuture<'js, T> ⓘ
futures
only.Convert self into a future which will return ready if the wrapped value isn’t a promise,
otherwise it will handle the promise like the future returned from
Promise::into_future
.
Trait Implementations§
Source§impl<'js> Clone for MaybePromise<'js>
impl<'js> Clone for MaybePromise<'js>
Source§fn clone(&self) -> MaybePromise<'js>
fn clone(&self) -> MaybePromise<'js>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<'js> Debug for MaybePromise<'js>
impl<'js> Debug for MaybePromise<'js>
Source§impl<'js> FromJs<'js> for MaybePromise<'js>
impl<'js> FromJs<'js> for MaybePromise<'js>
Source§impl<'js> Hash for MaybePromise<'js>
impl<'js> Hash for MaybePromise<'js>
Source§impl<'js> IntoJs<'js> for MaybePromise<'js>
impl<'js> IntoJs<'js> for MaybePromise<'js>
Source§impl<'js> PartialEq for MaybePromise<'js>
impl<'js> PartialEq for MaybePromise<'js>
impl<'js> Eq for MaybePromise<'js>
impl<'js> StructuralPartialEq for MaybePromise<'js>
Auto Trait Implementations§
impl<'js> Freeze for MaybePromise<'js>
impl<'js> RefUnwindSafe for MaybePromise<'js>
impl<'js> !Send for MaybePromise<'js>
impl<'js> !Sync for MaybePromise<'js>
impl<'js> Unpin for MaybePromise<'js>
impl<'js> !UnwindSafe for MaybePromise<'js>
Blanket Implementations§
Source§impl<'js, T> AsProperty<'js, T> for Twhere
T: IntoJs<'js>,
impl<'js, T> AsProperty<'js, T> for Twhere
T: IntoJs<'js>,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<'js, T> FromParam<'js> for Twhere
T: FromJs<'js>,
impl<'js, T> FromParam<'js> for Twhere
T: FromJs<'js>,
Source§fn param_requirement() -> ParamRequirement
fn param_requirement() -> ParamRequirement
Source§fn from_param<'a>(params: &mut ParamsAccessor<'a, 'js>) -> Result<T, Error>
fn from_param<'a>(params: &mut ParamsAccessor<'a, 'js>) -> Result<T, Error>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more