Struct rquickjs::promise::MaybePromise
source · 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>) -> MaybePromise<'js>
pub fn from_value(value: Value<'js>) -> MaybePromise<'js>
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>(&self) -> Option<Result<T, Error>>where
T: FromJs<'js>,
pub fn result<T>(&self) -> Option<Result<T, Error>>where
T: FromJs<'js>,
Returns the value if self isn’t a promise, otherwise calls Promise::result
on the promise.
sourcepub fn finish<T>(&self) -> Result<T, Error>where
T: FromJs<'js>,
pub fn finish<T>(&self) -> Result<T, Error>where
T: FromJs<'js>,
Returns the value if self isn’t a promise, otherwise calls Promise::finish
on the promise.
sourcepub fn into_future<T>(self) -> MaybePromiseFuture<'js, T> ⓘwhere
T: FromJs<'js>,
Available on crate feature futures
only.
pub fn into_future<T>(self) -> MaybePromiseFuture<'js, T> ⓘwhere
T: FromJs<'js>,
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>
source§fn eq(&self, other: &MaybePromise<'js>) -> bool
fn eq(&self, other: &MaybePromise<'js>) -> bool
self
and other
values to be equal, and is used
by ==
.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<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