MCPcopy Index your code
hub / github.com/darfink/tap-rs

github.com/darfink/tap-rs @0.4.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release 0.4.0 ↗ · + Follow
27 symbols 52 edges 4 files 6 documented · 22%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

tap

Documentation crates.io version Language (Rust)

A simple crate exposing tapping functionality for all types, and extended functionality for Option, Result & Future. Often useful for logging.

The tap operation takes, and then returns, full ownership of the variable being tapped. This means that the closure may have mutable access to the variable, even if the variable was previously immutable. This prevents accidental mutation.

Features

  • future - Exposes the TapFutureOps trait, providing tap_ready, tap_not_ready & tap_err (requires the futures crate).

Futures do not provide mutable access for tap closures.

  • nom3 - Exposes the TapNomOps trait, which provides tap_done, tap_error, and tap_incomplete on their respective variants of nom::IResult.

Example

extern crate tap;

use tap::*;

fn filter_map() {
    let values: &[Result<i32, &str>] = &[Ok(3), Err("foo"), Err("bar"), Ok(8)];

    let _ = values.iter().filter_map(|result| {
        // It is especially useful in filter maps, allowing error information to
        // be logged/printed before the information is discarded.
        result.tap_err(|error| eprintln!("Invalid entry: {}", error)).ok()
    });
}

fn basic() {
    let mut foo = 5;

    // The `tap` extension can be used on all types
    if 10.tap(|v| foo += *v) > 0 {
        assert_eq!(foo, 15);
    }

    // Results have `tap_err` & `tap_ok` available.
    let _: Result<i32, i32> = Err(5).tap_err(|e| foo = *e);
    assert_eq!(foo, 5);

    // Options have `tap_some` & `tap_none` available.
    let _: Option<i32> = None.tap_none(|| foo = 10);
    assert_eq!(foo, 10);
}

fn mutable() {
    let base = [1, 2, 3];
    let mutated = base.tap(|arr| for elt in arr.iter_mut() {
        *elt *= 2;
    });
    // base was consumed and is out of scope.
    assert_eq!(mutated, [2, 4, 6]);
}

Extension points exported contracts — how you extend this code

TapBooleanOps (Interface)
Tap operations for `bool`. [1 implementers]
src/lib.rs
TapFutureOps (Interface)
Tap operations for `Future`, requires the feature `future`. [1 implementers]
src/future.rs
TapNomOps (Interface)
Tap operations for nom's `IResult`, requires the feature `nom3`. [1 implementers]
src/nom.rs
TapResultOps (Interface)
Tap operations for `Result`. [1 implementers]
src/lib.rs
TapOptionOps (Interface)
Tap operations for `Option`. [1 implementers]
src/lib.rs
TapOps (Interface)
Tap operations for all types. [1 implementers]
src/lib.rs

Core symbols most depended-on inside this repo

tap_err
called by 2
src/lib.rs
tap_none
called by 1
src/lib.rs
tap
called by 1
src/lib.rs
tap_ready
called by 1
src/future.rs
tap_not_ready
called by 1
src/future.rs
tap_err
called by 1
src/future.rs
tap_done
called by 1
src/nom.rs
tap_error
called by 1
src/nom.rs

Shape

Method 13
Function 8
Interface 6

Languages

Rust100%

Modules by API surface

src/lib.rs11 symbols
src/nom.rs7 symbols
src/future.rs7 symbols
tests/lib.rs2 symbols

For agents

$ claude mcp add tap-rs \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact