Movatterモバイル変換


[0]ホーム

URL:


Docs.rs

Tap

TraitTap 

Source
pub trait Tap
where 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§

Source

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

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.

Source

fntap_borrow<B>(self, func: implFnOnce(&B)) -> Self
where Self:Borrow<B>, B: ?Sized,

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.

Source

fntap_borrow_mut<B>(self, func: implFnOnce(&mut B)) -> Self
where Self:BorrowMut<B>, B: ?Sized,

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.

Source

fntap_ref<R>(self, func: implFnOnce(&R)) -> Self
where Self:AsRef<R>, R: ?Sized,

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.

Source

fntap_ref_mut<R>(self, func: implFnOnce(&mut R)) -> Self
where Self:AsMut<R>, R: ?Sized,

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.

Source

fntap_deref<T>(self, func: implFnOnce(&T)) -> Self
where Self:Deref<Target = T>, T: ?Sized,

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.

Source

fntap_deref_mut<T>(self, func: implFnOnce(&mut T)) -> Self
where Self:DerefMut +Deref<Target = T>, T: ?Sized,

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.

Source

fntap_dbg(self, func: implFnOnce(&Self)) -> Self

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

Source

fntap_mut_dbg(self, func: implFnOnce(&mut Self)) -> Self

Calls.tap_mut() only in debug builds, and is erased in releasebuilds.

Source

fntap_borrow_dbg<B>(self, func: implFnOnce(&B)) -> Self
where Self:Borrow<B>, B: ?Sized,

Calls.tap_borrow() only in debug builds, and is erased in releasebuilds.

Source

fntap_borrow_mut_dbg<B>(self, func: implFnOnce(&mut B)) -> Self
where Self:BorrowMut<B>, B: ?Sized,

Calls.tap_borrow_mut() only in debug builds, and is erased in releasebuilds.

Source

fntap_ref_dbg<R>(self, func: implFnOnce(&R)) -> Self
where Self:AsRef<R>, R: ?Sized,

Calls.tap_ref() only in debug builds, and is erased in releasebuilds.

Source

fntap_ref_mut_dbg<R>(self, func: implFnOnce(&mut R)) -> Self
where Self:AsMut<R>, R: ?Sized,

Calls.tap_ref_mut() only in debug builds, and is erased in releasebuilds.

Source

fntap_deref_dbg<T>(self, func: implFnOnce(&T)) -> Self
where Self:Deref<Target = T>, T: ?Sized,

Calls.tap_deref() only in debug builds, and is erased in releasebuilds.

Source

fntap_deref_mut_dbg<T>(self, func: implFnOnce(&mut T)) -> Self
where Self:DerefMut +Deref<Target = T>, T: ?Sized,

Calls.tap_deref_mut() 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.

Implementors§

Source§

impl<T>Tap for T
where T:Sized,


[8]ページ先頭

©2009-2025 Movatter.jp