Crate tap_trait[][src]

Expand description

Inspect and mutate values without leaving the method chain.

Example:

use tap_trait::Tap;
use pipe_trait::Pipe;
let result = 2i32
    .tap(|x| assert_eq!(x, 2))
    .tap_mut(|x| *x += 1)
    .tap(|x| assert_eq!(x, 3))
    .tap_mut(|x| *x *= 3)
    .tap(|x| assert_eq!(x, 9))
    .pipe(|x| -x)
    .tap(|x| assert_eq!(x, -9))
    .pipe_ref(ToString::to_string)
    .tap_ref(|x| assert_eq!(x, "-9"))
    .tap_mut(|x| *x += ".0")
    .tap_ref(|x| assert_eq!(x, "-9.0"));
assert_eq!(result, "-9.0");

Traits

All sized types implement this trait.