Struct boa_engine::object::builtins::JsPromise
source · pub struct JsPromise { /* private fields */ }
Expand description
An ECMAScript promise object.
Known as the concurrency primitive of ECMAScript, this is the main struct used to manipulate,
chain and inspect Promises
from Rust code.
§Examples
let context = &mut Context::default();
context.register_global_property(
js_string!("finally"),
false,
Attribute::all(),
);
let promise = JsPromise::new(
|resolvers, context| {
let result = js_string!("hello world!").into();
resolvers.resolve.call(
&JsValue::undefined(),
&[result],
context,
)?;
Ok(JsValue::undefined())
},
context,
);
let promise = promise
.then(
Some(
NativeFunction::from_fn_ptr(|_, args, _| {
Err(JsError::from_opaque(args.get_or_undefined(0).clone())
.into())
})
.to_js_function(context.realm()),
),
None,
context,
)
.catch(
NativeFunction::from_fn_ptr(|_, args, _| {
Ok(args.get_or_undefined(0).clone())
})
.to_js_function(context.realm()),
context,
)
.finally(
NativeFunction::from_fn_ptr(|_, _, context| {
context.global_object().clone().set(
js_string!("finally"),
JsValue::from(true),
true,
context,
)?;
Ok(JsValue::undefined())
})
.to_js_function(context.realm()),
context,
);
context.run_jobs();
assert_eq!(
promise.state(),
PromiseState::Fulfilled(js_string!("hello world!").into())
);
assert_eq!(
context
.global_object()
.clone()
.get(js_string!("finally"), context)?,
JsValue::from(true)
);
Implementations§
source§impl JsPromise
impl JsPromise
sourcepub fn new<F>(executor: F, context: &mut Context) -> Self
pub fn new<F>(executor: F, context: &mut Context) -> Self
Creates a new promise object from an executor function.
It is equivalent to calling the Promise()
constructor, which makes it share the same
execution semantics as the constructor:
- The executor function
executor
is called synchronously just after the promise is created. - The executor return value is ignored.
- Any error thrown within the execution of
executor
will call thereject
function of the newly created promise, unless eitherresolve
orreject
were already called beforehand.
executor
receives as an argument the ResolvingFunctions
needed to settle the promise,
which can be done by either calling the resolve
function or the reject
function.
§Examples
let context = &mut Context::default();
let promise = JsPromise::new(
|resolvers, context| {
let result = js_string!("hello world").into();
resolvers.resolve.call(
&JsValue::undefined(),
&[result],
context,
)?;
Ok(JsValue::undefined())
},
context,
);
context.run_jobs();
assert_eq!(
promise.state(),
PromiseState::Fulfilled(js_string!("hello world").into())
);
sourcepub fn new_pending(context: &mut Context) -> (Self, ResolvingFunctions)
pub fn new_pending(context: &mut Context) -> (Self, ResolvingFunctions)
Creates a new pending promise and returns it and its associated ResolvingFunctions
.
This can be useful when you want to manually settle a promise from Rust code, instead of
running an executor
function that automatically settles the promise on creation
(see JsPromise::new
).
§Examples
let context = &mut Context::default();
let (promise, resolvers) = JsPromise::new_pending(context);
assert_eq!(promise.state(), PromiseState::Pending);
resolvers
.reject
.call(&JsValue::undefined(), &[5.into()], context)?;
assert_eq!(promise.state(), PromiseState::Rejected(5.into()));
sourcepub fn from_object(object: JsObject) -> JsResult<Self>
pub fn from_object(object: JsObject) -> JsResult<Self>
Wraps an existing object with the JsPromise
interface, returning Err
if the object
is not a valid promise.
§Examples
let context = &mut Context::default();
let promise = context.eval(Source::from_bytes(
"new Promise((resolve, reject) => resolve())",
))?;
let promise = promise.as_object().cloned().unwrap();
let promise = JsPromise::from_object(promise)?;
assert_eq!(
promise.state(),
PromiseState::Fulfilled(JsValue::undefined())
);
assert!(JsPromise::from_object(JsObject::with_null_proto()).is_err());
sourcepub fn from_future<Fut>(future: Fut, context: &mut Context) -> Self
pub fn from_future<Fut>(future: Fut, context: &mut Context) -> Self
Creates a new JsPromise
from a Future
-like.
If you want to convert a Rust async function into an ECMAScript async function, see
NativeFunction::from_async_fn
.
§Examples
async fn f() -> JsResult<JsValue> {
Ok(JsValue::null())
}
let context = &mut Context::default();
let promise = JsPromise::from_future(f(), context);
context.run_jobs();
assert_eq!(promise.state(), PromiseState::Fulfilled(JsValue::null()));
sourcepub fn resolve<V: Into<JsValue>>(value: V, context: &mut Context) -> Self
pub fn resolve<V: Into<JsValue>>(value: V, context: &mut Context) -> Self
Resolves a JsValue
into a JsPromise
.
Equivalent to the Promise.resolve()
static method.
This function is mainly used to wrap a plain JsValue
into a fulfilled promise, but it can
also flatten nested layers of thenables, which essentially converts them into native
promises.
§Examples
let context = &mut Context::default();
let promise = JsPromise::resolve(js_string!("resolved!"), context);
assert_eq!(
promise.state(),
PromiseState::Fulfilled(js_string!("resolved!").into())
);
sourcepub fn reject<E: Into<JsError>>(error: E, context: &mut Context) -> Self
pub fn reject<E: Into<JsError>>(error: E, context: &mut Context) -> Self
Creates a JsPromise
that is rejected with the reason error
.
Equivalent to the Promise.reject
static method.
JsPromise::reject
is pretty similar to JsPromise::resolve
, with the difference that
it always wraps error
into a rejected promise, even if error
is a promise or a thenable.
§Examples
let context = &mut Context::default();
let promise = JsPromise::reject(
JsError::from_opaque(js_string!("oops!").into()),
context,
);
assert_eq!(
promise.state(),
PromiseState::Rejected(js_string!("oops!").into())
);
sourcepub fn state(&self) -> PromiseState
pub fn state(&self) -> PromiseState
Gets the current state of the promise.
§Examples
let context = &mut Context::default();
let promise = JsPromise::new_pending(context).0;
assert_eq!(promise.state(), PromiseState::Pending);
sourcepub fn then(
&self,
on_fulfilled: Option<JsFunction>,
on_rejected: Option<JsFunction>,
context: &mut Context
) -> Self
pub fn then( &self, on_fulfilled: Option<JsFunction>, on_rejected: Option<JsFunction>, context: &mut Context ) -> Self
Schedules callback functions to run when the promise settles.
Equivalent to the Promise.prototype.then
method.
The return value is a promise that is always pending on return, regardless of the current state of the original promise. Two handlers can be provided as callbacks to be executed when the original promise settles:
- If the original promise is fulfilled,
on_fulfilled
is called with the fulfillment value of the original promise. - If the original promise is rejected,
on_rejected
is called with the rejection reason of the original promise.
The return value of the handlers can be used to mutate the state of the created promise. If the callback:
- returns a value: the created promise gets fulfilled with the returned value.
- doesn’t return: the created promise gets fulfilled with undefined.
- throws: the created promise gets rejected with the thrown error as its value.
- returns a fulfilled promise: the created promise gets fulfilled with that promise’s value as its value.
- returns a rejected promise: the created promise gets rejected with that promise’s value as its value.
- returns another pending promise: the created promise remains pending but becomes settled with that promise’s value as its value immediately after that promise becomes settled.
§Examples
let context = &mut Context::default();
let promise = JsPromise::new(
|resolvers, context| {
resolvers.resolve.call(
&JsValue::undefined(),
&[255.255.into()],
context,
)?;
Ok(JsValue::undefined())
},
context,
)
.then(
Some(
NativeFunction::from_fn_ptr(|_, args, context| {
args.get_or_undefined(0)
.to_string(context)
.map(JsValue::from)
})
.to_js_function(context.realm()),
),
None,
context,
);
context.run_jobs();
assert_eq!(
promise.state(),
PromiseState::Fulfilled(js_string!("255.255").into())
);
sourcepub fn catch(&self, on_rejected: JsFunction, context: &mut Context) -> Self
pub fn catch(&self, on_rejected: JsFunction, context: &mut Context) -> Self
Schedules a callback to run when the promise is rejected.
Equivalent to the Promise.prototype.catch
method.
This is essentially a shortcut for calling promise.then(None, Some(function))
, which
only handles the error case and leaves the fulfilled case untouched.
§Examples
let context = &mut Context::default();
let promise = JsPromise::new(
|resolvers, context| {
let error = JsNativeError::typ().with_message("thrown");
let error = error.to_opaque(context);
resolvers.reject.call(
&JsValue::undefined(),
&[error.into()],
context,
)?;
Ok(JsValue::undefined())
},
context,
)
.catch(
NativeFunction::from_fn_ptr(|_, args, context| {
args.get_or_undefined(0)
.to_string(context)
.map(JsValue::from)
})
.to_js_function(context.realm()),
context,
);
context.run_jobs();
assert_eq!(
promise.state(),
PromiseState::Fulfilled(js_string!("TypeError: thrown").into())
);
sourcepub fn finally(&self, on_finally: JsFunction, context: &mut Context) -> Self
pub fn finally(&self, on_finally: JsFunction, context: &mut Context) -> Self
Schedules a callback to run when the promise is rejected.
Equivalent to the Promise.prototype.finally()
method.
While this could be seen as a shortcut for calling promise.then(Some(function), Some(function))
,
it has slightly different semantics than then
:
on_finally
doesn’t receive any argument, unlikeon_fulfilled
andon_rejected
.finally()
is transparent; a call likePromise.resolve("first").finally(() => "second")
returns a promise fulfilled with the value"first"
, which would return"second"
iffinally
was a shortcut ofthen
.
§Examples
let context = &mut Context::default();
context.register_global_property(
js_string!("finally"),
false,
Attribute::all(),
)?;
let promise = JsPromise::new(
|resolvers, context| {
let error = JsNativeError::typ().with_message("thrown");
let error = error.to_opaque(context);
resolvers.reject.call(
&JsValue::undefined(),
&[error.into()],
context,
)?;
Ok(JsValue::undefined())
},
context,
)
.finally(
NativeFunction::from_fn_ptr(|_, _, context| {
context.global_object().clone().set(
js_string!("finally"),
JsValue::from(true),
true,
context,
)?;
Ok(JsValue::undefined())
})
.to_js_function(context.realm()),
context,
);
context.run_jobs();
assert_eq!(
context
.global_object()
.clone()
.get(js_string!("finally"), context)?,
JsValue::from(true)
);
sourcepub fn all<I>(promises: I, context: &mut Context) -> Selfwhere
I: IntoIterator<Item = Self>,
pub fn all<I>(promises: I, context: &mut Context) -> Selfwhere
I: IntoIterator<Item = Self>,
Waits for a list of promises to settle with fulfilled values, rejecting the aggregate promise when any of the inner promises is rejected.
Equivalent to the Promise.all
static method.
§Examples
let context = &mut Context::default();
let promise1 = JsPromise::all(
[
JsPromise::resolve(0, context),
JsPromise::resolve(2, context),
JsPromise::resolve(4, context),
],
context,
);
let promise2 = JsPromise::all(
[
JsPromise::resolve(1, context),
JsPromise::reject(JsNativeError::typ(), context),
JsPromise::resolve(3, context),
],
context,
);
context.run_jobs();
let array = promise1
.state()
.as_fulfilled()
.and_then(JsValue::as_object)
.unwrap()
.clone();
let array = JsArray::from_object(array)?;
assert_eq!(array.at(0, context)?, 0.into());
assert_eq!(array.at(1, context)?, 2.into());
assert_eq!(array.at(2, context)?, 4.into());
let error = promise2.state().as_rejected().unwrap().clone();
assert_eq!(error.to_string(context)?, js_string!("TypeError"));
sourcepub fn all_settled<I>(promises: I, context: &mut Context) -> Selfwhere
I: IntoIterator<Item = Self>,
pub fn all_settled<I>(promises: I, context: &mut Context) -> Selfwhere
I: IntoIterator<Item = Self>,
Waits for a list of promises to settle, fulfilling with an array of the outcomes of every promise.
Equivalent to the Promise.allSettled
static method.
§Examples
let context = &mut Context::default();
let promise = JsPromise::all_settled(
[
JsPromise::resolve(1, context),
JsPromise::reject(JsNativeError::typ(), context),
JsPromise::resolve(3, context),
],
context,
);
context.run_jobs();
let array = promise
.state()
.as_fulfilled()
.and_then(JsValue::as_object)
.unwrap()
.clone();
let array = JsArray::from_object(array)?;
let a = array.at(0, context)?.as_object().unwrap().clone();
assert_eq!(
a.get(js_string!("status"), context)?,
js_string!("fulfilled").into()
);
assert_eq!(a.get(js_string!("value"), context)?, 1.into());
let b = array.at(1, context)?.as_object().unwrap().clone();
assert_eq!(
b.get(js_string!("status"), context)?,
js_string!("rejected").into()
);
assert_eq!(
b.get(js_string!("reason"), context)?.to_string(context)?,
js_string!("TypeError")
);
let c = array.at(2, context)?.as_object().unwrap().clone();
assert_eq!(
c.get(js_string!("status"), context)?,
js_string!("fulfilled").into()
);
assert_eq!(c.get(js_string!("value"), context)?, 3.into());
sourcepub fn any<I>(promises: I, context: &mut Context) -> Selfwhere
I: IntoIterator<Item = Self>,
pub fn any<I>(promises: I, context: &mut Context) -> Selfwhere
I: IntoIterator<Item = Self>,
Returns the first promise that fulfills from a list of promises.
Equivalent to the Promise.any
static method.
If after settling all promises in promises
there isn’t a fulfilled promise, the returned
promise will be rejected with an AggregatorError
containing the rejection values of every
promise; this includes the case where promises
is an empty iterator.
§Examples
let context = &mut Context::default();
let promise = JsPromise::any(
[
JsPromise::reject(JsNativeError::syntax(), context),
JsPromise::reject(JsNativeError::typ(), context),
JsPromise::resolve(js_string!("fulfilled"), context),
JsPromise::reject(JsNativeError::range(), context),
],
context,
);
context.run_jobs();
assert_eq!(
promise.state(),
PromiseState::Fulfilled(js_string!("fulfilled").into())
);
sourcepub fn race<I>(promises: I, context: &mut Context) -> Selfwhere
I: IntoIterator<Item = Self>,
pub fn race<I>(promises: I, context: &mut Context) -> Selfwhere
I: IntoIterator<Item = Self>,
Returns the first promise that settles from a list of promises.
Equivalent to the Promise.race
static method.
If the provided iterator is empty, the returned promise will remain on the pending state forever.
§Examples
let context = &mut Context::default();
let (a, resolvers_a) = JsPromise::new_pending(context);
let (b, resolvers_b) = JsPromise::new_pending(context);
let (c, resolvers_c) = JsPromise::new_pending(context);
let promise = JsPromise::race([a, b, c], context);
resolvers_b
.reject
.call(&JsValue::undefined(), &[], context)?;
resolvers_a
.resolve
.call(&JsValue::undefined(), &[5.into()], context)?;
resolvers_c.reject.call(
&JsValue::undefined(),
&[js_string!("c error").into()],
context,
)?;
context.run_jobs();
assert_eq!(
promise.state(),
PromiseState::Rejected(JsValue::undefined())
);
sourcepub fn into_js_future(self, context: &mut Context) -> JsFuture ⓘ
pub fn into_js_future(self, context: &mut Context) -> JsFuture ⓘ
Creates a JsFuture
from this JsPromise
.
The returned JsFuture
implements Future
, which means it can be await
ed within Rust’s
async contexts (async functions and async blocks).
§Examples
let context = &mut Context::default();
let (promise, resolvers) = JsPromise::new_pending(context);
let promise_future = promise.into_js_future(context);
let future1 = async move { promise_future.await };
let future2 = async move {
resolvers
.resolve
.call(&JsValue::undefined(), &[10.into()], context)?;
context.run_jobs();
Ok::<(), JsError>(())
};
let (result1, result2) = future::block_on(future::zip(future1, future2));
assert_eq!(result1, Ok(JsValue::from(10)));
assert_eq!(result2, Ok(()));
Methods from Deref<Target = JsObject>§
sourcepub fn downcast_ref<T: NativeObject>(&self) -> Option<Ref<'_, T>>
pub fn downcast_ref<T: NativeObject>(&self) -> Option<Ref<'_, T>>
Downcasts a reference to the object,
if the object is of type T
.
§Panics
Panics if the object is currently mutably borrowed.
sourcepub fn downcast_mut<T: NativeObject>(
&self
) -> Option<RefMut<'_, ErasedObject, T>>
pub fn downcast_mut<T: NativeObject>( &self ) -> Option<RefMut<'_, ErasedObject, T>>
Downcasts a mutable reference to the object,
if the object is type native object type T
.
§Panics
Panics if the object is currently borrowed.
sourcepub fn is<T: NativeObject>(&self) -> bool
pub fn is<T: NativeObject>(&self) -> bool
Checks if this object is an instance of a certain NativeObject
.
§Panics
Panics if the object is currently mutably borrowed.
sourcepub fn is_ordinary(&self) -> bool
pub fn is_ordinary(&self) -> bool
sourcepub fn to_property_descriptor(
&self,
context: &mut Context
) -> JsResult<PropertyDescriptor>
pub fn to_property_descriptor( &self, context: &mut Context ) -> JsResult<PropertyDescriptor>
sourcepub fn copy_data_properties<K>(
&self,
source: &JsValue,
excluded_keys: Vec<K>,
context: &mut Context
) -> JsResult<()>where
K: Into<PropertyKey>,
pub fn copy_data_properties<K>(
&self,
source: &JsValue,
excluded_keys: Vec<K>,
context: &mut Context
) -> JsResult<()>where
K: Into<PropertyKey>,
sourcepub fn borrow(&self) -> Ref<'_, Object<T>>
pub fn borrow(&self) -> Ref<'_, Object<T>>
Immutably borrows the Object
.
The borrow lasts until the returned Ref
exits scope.
Multiple immutable borrows can be taken out at the same time.
§Panics
Panics if the object is currently mutably borrowed.
sourcepub fn borrow_mut(&self) -> RefMut<'_, Object<T>, Object<T>>
pub fn borrow_mut(&self) -> RefMut<'_, Object<T>, Object<T>>
Mutably borrows the Object.
The borrow lasts until the returned RefMut
exits scope.
The object cannot be borrowed while this borrow is active.
§Panics
Panics if the object is currently borrowed.
sourcepub fn try_borrow(&self) -> StdResult<Ref<'_, Object<T>>, BorrowError>
pub fn try_borrow(&self) -> StdResult<Ref<'_, Object<T>>, BorrowError>
Immutably borrows the Object
, returning an error if the value is currently mutably borrowed.
The borrow lasts until the returned GcCellRef
exits scope.
Multiple immutable borrows can be taken out at the same time.
This is the non-panicking variant of borrow
.
sourcepub fn try_borrow_mut(
&self
) -> StdResult<RefMut<'_, Object<T>, Object<T>>, BorrowMutError>
pub fn try_borrow_mut( &self ) -> StdResult<RefMut<'_, Object<T>, Object<T>>, BorrowMutError>
Mutably borrows the object, returning an error if the value is currently borrowed.
The borrow lasts until the returned GcCellRefMut
exits scope.
The object be borrowed while this borrow is active.
This is the non-panicking variant of borrow_mut
.
sourcepub fn prototype(&self) -> JsPrototype
pub fn prototype(&self) -> JsPrototype
sourcepub fn set_prototype(&self, prototype: JsPrototype) -> bool
pub fn set_prototype(&self, prototype: JsPrototype) -> bool
sourcepub fn insert_property<K, P>(&self, key: K, property: P) -> bool
pub fn insert_property<K, P>(&self, key: K, property: P) -> bool
Inserts a field in the object properties
without checking if it’s writable.
If a field was already in the object with the same name, than true
is returned
with that field, otherwise false
is returned.
sourcepub fn is_callable(&self) -> bool
pub fn is_callable(&self) -> bool
It determines if Object is a callable function with a [[Call]]
internal method.
More information:
sourcepub fn is_constructor(&self) -> bool
pub fn is_constructor(&self) -> bool
It determines if Object is a function object with a [[Construct]]
internal method.
More information:
sourcepub fn is_extensible(&self, context: &mut Context) -> JsResult<bool>
pub fn is_extensible(&self, context: &mut Context) -> JsResult<bool>
sourcepub fn get<K>(&self, key: K, context: &mut Context) -> JsResult<JsValue>where
K: Into<PropertyKey>,
pub fn get<K>(&self, key: K, context: &mut Context) -> JsResult<JsValue>where
K: Into<PropertyKey>,
sourcepub fn set<K, V>(
&self,
key: K,
value: V,
throw: bool,
context: &mut Context
) -> JsResult<bool>
pub fn set<K, V>( &self, key: K, value: V, throw: bool, context: &mut Context ) -> JsResult<bool>
sourcepub fn create_data_property<K, V>(
&self,
key: K,
value: V,
context: &mut Context
) -> JsResult<bool>
pub fn create_data_property<K, V>( &self, key: K, value: V, context: &mut Context ) -> JsResult<bool>
sourcepub fn create_data_property_or_throw<K, V>(
&self,
key: K,
value: V,
context: &mut Context
) -> JsResult<bool>
pub fn create_data_property_or_throw<K, V>( &self, key: K, value: V, context: &mut Context ) -> JsResult<bool>
sourcepub fn define_property_or_throw<K, P>(
&self,
key: K,
desc: P,
context: &mut Context
) -> JsResult<bool>
pub fn define_property_or_throw<K, P>( &self, key: K, desc: P, context: &mut Context ) -> JsResult<bool>
sourcepub fn delete_property_or_throw<K>(
&self,
key: K,
context: &mut Context
) -> JsResult<bool>where
K: Into<PropertyKey>,
pub fn delete_property_or_throw<K>(
&self,
key: K,
context: &mut Context
) -> JsResult<bool>where
K: Into<PropertyKey>,
Defines the property or throws a TypeError
if the operation fails.
More information:
sourcepub fn has_property<K>(&self, key: K, context: &mut Context) -> JsResult<bool>where
K: Into<PropertyKey>,
pub fn has_property<K>(&self, key: K, context: &mut Context) -> JsResult<bool>where
K: Into<PropertyKey>,
sourcepub fn has_own_property<K>(
&self,
key: K,
context: &mut Context
) -> JsResult<bool>where
K: Into<PropertyKey>,
pub fn has_own_property<K>(
&self,
key: K,
context: &mut Context
) -> JsResult<bool>where
K: Into<PropertyKey>,
sourcepub fn call(
&self,
this: &JsValue,
args: &[JsValue],
context: &mut Context
) -> JsResult<JsValue>
pub fn call( &self, this: &JsValue, args: &[JsValue], context: &mut Context ) -> JsResult<JsValue>
Call ( F, V [ , argumentsList ] )
§Panics
Panics if the object is currently mutably borrowed.
More information:
sourcepub fn construct(
&self,
args: &[JsValue],
new_target: Option<&Self>,
context: &mut Context
) -> JsResult<Self>
pub fn construct( &self, args: &[JsValue], new_target: Option<&Self>, context: &mut Context ) -> JsResult<Self>
Construct ( F [ , argumentsList [ , newTarget ] ] )
Construct an instance of this object with the specified arguments.
§Panics
Panics if the object is currently mutably borrowed.
More information:
sourcepub fn set_integrity_level(
&self,
level: IntegrityLevel,
context: &mut Context
) -> JsResult<bool>
pub fn set_integrity_level( &self, level: IntegrityLevel, context: &mut Context ) -> JsResult<bool>
sourcepub fn test_integrity_level(
&self,
level: IntegrityLevel,
context: &mut Context
) -> JsResult<bool>
pub fn test_integrity_level( &self, level: IntegrityLevel, context: &mut Context ) -> JsResult<bool>
Trait Implementations§
source§impl Trace for JsPromise
impl Trace for JsPromise
source§unsafe fn trace_non_roots(&self)
unsafe fn trace_non_roots(&self)
source§fn run_finalizer(&self)
fn run_finalizer(&self)
Finalize::finalize
on this object and all
contained subobjects.Auto Trait Implementations§
impl !RefUnwindSafe for JsPromise
impl !Send for JsPromise
impl !Sync for JsPromise
impl Unpin for JsPromise
impl !UnwindSafe for JsPromise
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
source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moresource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moresource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R ) -> R
source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.source§impl<T> Tap for T
impl<T> Tap for T
source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read moresource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read moresource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read moresource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read moresource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read moresource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read moresource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.