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§
- Result
Group - An accumulator for
Resultvalues that collects all successes and errors.
Traits§
- Option
Ext - Extension trait for
Option<T>providing tap and fallible conversion operations. - Result
Ext - Extension trait for
Result<T, E>providing tap, map, and recovery operations.
Functions§
- collect_
results - Collects all results from an iterator, returning either all
Okvalues or allErrvalues. - partition
- Separates an iterator of
Resultvalues into a tuple of successes and errors.