Skip to main content

Crate philiprehberger_result_ext

Crate philiprehberger_result_ext 

Source
Expand description

§philiprehberger-result-ext

Extension traits for Result and Option with tap, map, and error accumulation.

This crate is no_std compatible (requires alloc for Vec-based APIs).

§Examples

use philiprehberger_result_ext::{ResultExt, OptionExt, collect_results, partition, ResultGroup};

// Tap for side effects
let value = Ok::<_, &str>(42)
    .tap_ok(|v| assert_eq!(*v, 42));

// Map both variants at once
let result: Result<String, usize> = Ok("hello")
    .map_both(|s| s.to_uppercase(), |e: &str| e.len());
assert_eq!(result, Ok("HELLO".to_string()));

// Collect all errors from an iterator
let results = vec![Ok(1), Err("a"), Ok(3), Err("b")];
let outcome = collect_results(results);
assert_eq!(outcome, Err(vec!["a", "b"]));

Structs§

ResultGroup
An accumulator for Result values that collects all successes and errors.

Traits§

OptionExt
Extension trait for Option<T> providing tap and fallible conversion operations.
ResultExt
Extension trait for Result<T, E> providing tap, map, and recovery operations.

Functions§

collect_results
Collects all results from an iterator, returning either all Ok values or all Err values.
partition
Separates an iterator of Result values into a tuple of successes and errors.