pub trait Tapwhere Self:Sized,{Show 16 methods
// Provided methods fntap(self, func: implFnOnce(&Self)) -> Self { ... } fntap_mut(self, func: implFnOnce(&mut Self)) -> Self { ... } fntap_borrow<B>(self, func: implFnOnce(&B)) -> Selfwhere Self:Borrow<B>, B: ?Sized { ... } fntap_borrow_mut<B>(self, func: implFnOnce(&mut B)) -> Selfwhere Self:BorrowMut<B>, B: ?Sized { ... } fntap_ref<R>(self, func: implFnOnce(&R)) -> Selfwhere Self:AsRef<R>, R: ?Sized { ... } fntap_ref_mut<R>(self, func: implFnOnce(&mut R)) -> Selfwhere Self:AsMut<R>, R: ?Sized { ... } fntap_deref<T>(self, func: implFnOnce(&T)) -> Selfwhere Self:Deref<Target = T>, T: ?Sized { ... } fntap_deref_mut<T>(self, func: implFnOnce(&mut T)) -> Selfwhere Self:DerefMut +Deref<Target = T>, T: ?Sized { ... } fntap_dbg(self, func: implFnOnce(&Self)) -> Self { ... } fntap_mut_dbg(self, func: implFnOnce(&mut Self)) -> Self { ... } fntap_borrow_dbg<B>(self, func: implFnOnce(&B)) -> Selfwhere Self:Borrow<B>, B: ?Sized { ... } fntap_borrow_mut_dbg<B>(self, func: implFnOnce(&mut B)) -> Selfwhere Self:BorrowMut<B>, B: ?Sized { ... } fntap_ref_dbg<R>(self, func: implFnOnce(&R)) -> Selfwhere Self:AsRef<R>, R: ?Sized { ... } fntap_ref_mut_dbg<R>(self, func: implFnOnce(&mut R)) -> Selfwhere Self:AsMut<R>, R: ?Sized { ... } fntap_deref_dbg<T>(self, func: implFnOnce(&T)) -> Selfwhere Self:Deref<Target = T>, T: ?Sized { ... } fntap_deref_mut_dbg<T>(self, func: implFnOnce(&mut T)) -> Selfwhere Self:DerefMut +Deref<Target = T>, T: ?Sized { ... }}Expand description
Point-free value inspection and modification.
This trait provides methods that permit viewing the value of an expressionwithout requiring a newlet binding or any other alterations to the originalcode other than insertion of the.tap() call.
The methods in this trait do not perform any view conversions on the value theyreceive; it is borrowed and passed directly to the effect argument.
Provided Methods§
Sourcefntap(self, func: implFnOnce(&Self)) -> Self
fntap(self, func: implFnOnce(&Self)) -> Self
Immutable access to a value.
This function permits a value to be viewed by some inspecting functionwithout affecting the overall shape of the expression that contains thismethod call. It is useful for attaching assertions or logging pointsinto a multi-part expression.
§Examples
Here we use.tap() to attach logging tracepoints to each stage of avalue-processing pipeline.
usetap::tap::Tap;letend = make_value()// this line has no effect on the rest of the code.tap(|v|log!("The produced value was: {}", v)) .process_value();Sourcefntap_mut(self, func: implFnOnce(&mut Self)) -> Self
fntap_mut(self, func: implFnOnce(&mut Self)) -> Self
Mutable access to a value.
This function permits a value to be modified by some function withoutaffecting the overall shape of the expression that contains this methodcall. It is useful for attaching modifier functions that have an&mut Self -> () signature to an expression, without requiring anexplicitlet mut binding.
§Examples
Here we use.tap_mut() to sort an array without requring multiplebindings.
usetap::tap::Tap;letsorted = [1i32,5,2,4,3] .tap_mut(|arr| arr.sort());assert_eq!(sorted, [1,2,3,4,5]);Without tapping, this would be written as
letmutreceived = [1,5,2,4,3];received.sort();letsorted = received;The mutable tap is a convenient alternative when the expression toproduce the collection is more complex, for example, an iteratorpipeline collected into a vector.
Sourcefntap_borrow<B>(self, func: implFnOnce(&B)) -> Self
fntap_borrow<B>(self, func: implFnOnce(&B)) -> Self
Immutable access to theBorrow<B> of a value.
This function is identcal toTap::tap, except that the effectfunction recevies an&B produced byBorrow::<B>::borrow, rather thanan&Self.
Sourcefntap_borrow_mut<B>(self, func: implFnOnce(&mut B)) -> Self
fntap_borrow_mut<B>(self, func: implFnOnce(&mut B)) -> Self
Mutable access to theBorrowMut<B> of a value.
This function is identical toTap::tap_mut, except that the effectfunction receives an&mut B produced byBorrowMut::<B>::borrow_mut,rather than an&mut Self.
Sourcefntap_ref<R>(self, func: implFnOnce(&R)) -> Self
fntap_ref<R>(self, func: implFnOnce(&R)) -> Self
Immutable access to theAsRef<R> view of a value.
This function is identical toTap::tap, except that the effectfunction receives an&R produced byAsRef::<R>::as_ref, rather thanan&Self.
Sourcefntap_ref_mut<R>(self, func: implFnOnce(&mut R)) -> Self
fntap_ref_mut<R>(self, func: implFnOnce(&mut R)) -> Self
Mutable access to theAsMut<R> view of a value.
This function is identical toTap::tap_mut, except that the effectfunction receives an&mut R produced byAsMut::<R>::as_mut, ratherthan an&mut Self.
Sourcefntap_deref<T>(self, func: implFnOnce(&T)) -> Self
fntap_deref<T>(self, func: implFnOnce(&T)) -> Self
Immutable access to theDeref::Target of a value.
This function is identical toTap::tap, except that the effectfunction receives an&Self::Target produced byDeref::deref, ratherthan an&Self.
Sourcefntap_deref_mut<T>(self, func: implFnOnce(&mut T)) -> Self
fntap_deref_mut<T>(self, func: implFnOnce(&mut T)) -> Self
Mutable access to theDeref::Target of a value.
This function is identical toTap::tap_mut, except that the effectfunction receives an&mut Self::Target produced byDerefMut::deref_mut, rather than an&mut Self.
Sourcefntap_dbg(self, func: implFnOnce(&Self)) -> Self
fntap_dbg(self, func: implFnOnce(&Self)) -> Self
Calls.tap() only in debug builds, and is erased in release builds.
Sourcefntap_mut_dbg(self, func: implFnOnce(&mut Self)) -> Self
fntap_mut_dbg(self, func: implFnOnce(&mut Self)) -> Self
Calls.tap_mut() only in debug builds, and is erased in releasebuilds.
Sourcefntap_borrow_dbg<B>(self, func: implFnOnce(&B)) -> Self
fntap_borrow_dbg<B>(self, func: implFnOnce(&B)) -> Self
Calls.tap_borrow() only in debug builds, and is erased in releasebuilds.
Sourcefntap_borrow_mut_dbg<B>(self, func: implFnOnce(&mut B)) -> Self
fntap_borrow_mut_dbg<B>(self, func: implFnOnce(&mut B)) -> Self
Calls.tap_borrow_mut() only in debug builds, and is erased in releasebuilds.
Sourcefntap_ref_dbg<R>(self, func: implFnOnce(&R)) -> Self
fntap_ref_dbg<R>(self, func: implFnOnce(&R)) -> Self
Calls.tap_ref() only in debug builds, and is erased in releasebuilds.
Sourcefntap_ref_mut_dbg<R>(self, func: implFnOnce(&mut R)) -> Self
fntap_ref_mut_dbg<R>(self, func: implFnOnce(&mut R)) -> Self
Calls.tap_ref_mut() only in debug builds, and is erased in releasebuilds.
Sourcefntap_deref_dbg<T>(self, func: implFnOnce(&T)) -> Self
fntap_deref_dbg<T>(self, func: implFnOnce(&T)) -> Self
Calls.tap_deref() only in debug builds, and is erased in releasebuilds.
Dyn Compatibility§
This trait isnotdyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.