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

source

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 the reject function of the newly created promise, unless either resolve or reject 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())
);
source

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()));
source

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());
source

pub fn from_future<Fut>(future: Fut, context: &mut Context) -> Self
where Fut: IntoFuture<Output = JsResult<JsValue>> + 'static,

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()));
source

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())
);
source

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())
);
source

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);
source

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())
);
source

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())
);
source

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, unlike on_fulfilled and on_rejected.
  • finally() is transparent; a call like Promise.resolve("first").finally(() => "second") returns a promise fulfilled with the value "first", which would return "second" if finally was a shortcut of then.
§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)
);
source

pub fn all<I>(promises: I, context: &mut Context) -> Self
where 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"));
source

pub fn all_settled<I>(promises: I, context: &mut Context) -> Self
where 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());
source

pub fn any<I>(promises: I, context: &mut Context) -> Self
where 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())
);
source

pub fn race<I>(promises: I, context: &mut Context) -> Self
where 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())
);
source

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 awaited 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>§

source

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.

source

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.

source

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.

source

pub fn is_ordinary(&self) -> bool

Checks if it’s an ordinary object.

§Panics

Panics if the object is currently mutably borrowed.

source

pub fn is_array(&self) -> bool

Checks if it’s an Array object.

source

pub fn to_property_descriptor( &self, context: &mut Context ) -> JsResult<PropertyDescriptor>

The abstract operation ToPropertyDescriptor.

More information:

source

pub fn copy_data_properties<K>( &self, source: &JsValue, excluded_keys: Vec<K>, context: &mut Context ) -> JsResult<()>
where K: Into<PropertyKey>,

7.3.25 CopyDataProperties ( target, source, excludedItems )

More information:

source

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.

source

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.

source

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.

source

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.

source

pub fn prototype(&self) -> JsPrototype

Get the prototype of the object.

§Panics

Panics if the object is currently mutably borrowed.

source

pub fn set_prototype(&self, prototype: JsPrototype) -> bool

Set the prototype of the object.

§Panics

Panics if the object is currently mutably borrowed

source

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.

source

pub fn is_callable(&self) -> bool

It determines if Object is a callable function with a [[Call]] internal method.

More information:

source

pub fn is_constructor(&self) -> bool

It determines if Object is a function object with a [[Construct]] internal method.

More information:

source

pub fn is_extensible(&self, context: &mut Context) -> JsResult<bool>

Check if object is extensible.

More information:

source

pub fn get<K>(&self, key: K, context: &mut Context) -> JsResult<JsValue>
where K: Into<PropertyKey>,

Get property from object or throw.

More information:

source

pub fn set<K, V>( &self, key: K, value: V, throw: bool, context: &mut Context ) -> JsResult<bool>
where K: Into<PropertyKey>, V: Into<JsValue>,

set property of object or throw if bool flag is passed.

More information:

source

pub fn create_data_property<K, V>( &self, key: K, value: V, context: &mut Context ) -> JsResult<bool>
where K: Into<PropertyKey>, V: Into<JsValue>,

Create data property

More information:

source

pub fn create_data_property_or_throw<K, V>( &self, key: K, value: V, context: &mut Context ) -> JsResult<bool>
where K: Into<PropertyKey>, V: Into<JsValue>,

Create data property or throw

More information:

source

pub fn define_property_or_throw<K, P>( &self, key: K, desc: P, context: &mut Context ) -> JsResult<bool>

Define property or throw.

More information:

source

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:

source

pub fn has_property<K>(&self, key: K, context: &mut Context) -> JsResult<bool>
where K: Into<PropertyKey>,

Check if object has property.

More information:

source

pub fn has_own_property<K>( &self, key: K, context: &mut Context ) -> JsResult<bool>
where K: Into<PropertyKey>,

Check if object has an own property.

More information:

source

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:

source

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:

source

pub fn set_integrity_level( &self, level: IntegrityLevel, context: &mut Context ) -> JsResult<bool>

Make the object sealed or frozen.

More information:

source

pub fn test_integrity_level( &self, level: IntegrityLevel, context: &mut Context ) -> JsResult<bool>

Check if the object is sealed or frozen.

More information:

Trait Implementations§

source§

impl Clone for JsPromise

source§

fn clone(&self) -> JsPromise

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for JsPromise

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Deref for JsPromise

§

type Target = JsObject

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl Drop for JsPromise

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl Finalize for JsPromise

source§

fn finalize(&self)

Cleanup logic for a type.
source§

impl From<JsPromise> for JsObject

source§

fn from(o: JsPromise) -> Self

Converts to this type from the input type.
source§

impl From<JsPromise> for JsValue

source§

fn from(o: JsPromise) -> Self

Converts to this type from the input type.
source§

impl Trace for JsPromise

source§

unsafe fn trace(&self, tracer: &mut Tracer)

Marks all contained Gcs. Read more
source§

unsafe fn trace_non_roots(&self)

Trace handles located in GC heap, and mark them as non root. Read more
source§

fn run_finalizer(&self)

Runs Finalize::finalize on this object and all contained subobjects.
source§

impl TryFromJs for JsPromise

source§

fn try_from_js(value: &JsValue, _context: &mut Context) -> JsResult<Self>

This function tries to convert a JavaScript value into Self.

Auto Trait Implementations§

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> Conv for T

source§

fn conv<T>(self) -> T
where Self: Into<T>,

Converts self into T using Into<T>. 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> Pipe for T
where T: ?Sized,

source§

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
where Self: Sized,

Pipes by value. This is generally the method you want to use. Read more
source§

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R
where R: 'a,

Borrows self and passes that borrow into the pipe function. Read more
source§

fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R
where R: 'a,

Mutably borrows self and passes that borrow into the pipe function. Read more
source§

fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
where Self: Borrow<B>, B: 'a + ?Sized, R: 'a,

Borrows self, then passes self.borrow() into the pipe function. Read more
source§

fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R ) -> R
where Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
source§

fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
where Self: AsRef<U>, U: 'a + ?Sized, R: 'a,

Borrows 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
where Self: AsMut<U>, U: 'a + ?Sized, R: 'a,

Mutably borrows 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
where Self: Deref<Target = T>, T: 'a + ?Sized, R: 'a,

Borrows self, then passes self.deref() into the pipe function.
source§

fn pipe_deref_mut<'a, T, R>( &'a mut self, func: impl FnOnce(&'a mut T) -> R ) -> R
where Self: DerefMut<Target = T> + Deref, T: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.deref_mut() into the pipe function.
source§

impl<T> Tap for T

source§

fn tap(self, func: impl FnOnce(&Self)) -> Self

Immutable access to a value. Read more
source§

fn tap_mut(self, func: impl FnOnce(&mut Self)) -> Self

Mutable access to a value. Read more
source§

fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Immutable access to the Borrow<B> of a value. Read more
source§

fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Mutable access to the BorrowMut<B> of a value. Read more
source§

fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Immutable access to the AsRef<R> view of a value. Read more
source§

fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Mutable access to the AsMut<R> view of a value. Read more
source§

fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Immutable access to the Deref::Target of a value. Read more
source§

fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Mutable access to the Deref::Target of a value. Read more
source§

fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self

Calls .tap() only in debug builds, and is erased in release builds.
source§

fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self

Calls .tap_mut() only in debug builds, and is erased in release builds.
source§

fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Calls .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
where Self: BorrowMut<B>, B: ?Sized,

Calls .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
where Self: AsRef<R>, R: ?Sized,

Calls .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
where Self: AsMut<R>, R: ?Sized,

Calls .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
where Self: Deref<Target = T>, T: ?Sized,

Calls .tap_deref() only in debug builds, and is erased in release builds.
source§

fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> TryConv for T

source§

fn try_conv<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

Attempts to convert self into T using TryInto<T>. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> ErasedDestructor for T
where T: 'static,

source§

impl<T> MaybeSendSync for T