[][src]Crate beau_collector

Collect all the errors from an iterator of Results into a Result with a single Error: Result<T, Error>.

The resultant Error has an error message with all the errors' messages each on a newline.

Examples:

use anyhow::{anyhow, Result};
use beau_collector::BeauCollector as _;

let x = vec![Ok(()), Err(anyhow!("woops")), Err(anyhow!("woops again"))];

let y: Result<Vec<()>> = x.into_iter().bcollect();

assert_eq!(y.unwrap_err().to_string(), "woops\nwoops again")

,

use anyhow::{anyhow, Result};
use std::collections::HashMap;
use beau_collector::BeauCollector as _;

let x = vec!["one", "two", "three", "four"];

let y: Result<HashMap<String, usize>> = x
    .iter()
    .map(|name: &&str| -> Result<(String, usize)> {
        let length = name.len();
        if length < 4 {
           Ok((name.to_string(), length))
        } else {
           Err(anyhow!("name \"{}\" has {} characters", name, length))
        }
    })
    .bcollect();

assert_eq!(
    y.unwrap_err().to_string(),
    "name \"three\" has 5 characters\nname \"four\" has 4 characters")

Traits

BeauCollector