1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//! # MapOk
//!
//! This crate provides the [`MapOk`] trait that allows mapping [`Ok`] variants in an iterator to a different type.
//!
//! # Examples
//!
//! ```
//! use std::num::ParseIntError;
//! use std::str::FromStr;
//! use map_ok::MapOk;
//!
//! struct Person {
//!     age: u8,
//! }
//!
//! impl Person {
//!     fn new(age: u8) -> Self {
//!         Person { age }
//!     }
//! }
//!
//! impl FromStr for Person {
//!     type Err = ParseIntError;
//!
//!     fn from_str(s: &str) -> Result<Self, Self::Err> {
//!         let age = u8::from_str(s)?;
//!         Ok(Person::new(age))
//!     }
//! }
//!
//! let input = vec!["10", "20", "x", "30"];
//! let mut iterator = input.iter()
//!     .map(|s| s.parse::<Person>())
//!     .map_ok(|p| p.age);
//!
//! assert_eq!(iterator.next(), Some(Ok(10)));
//! assert_eq!(iterator.next(), Some(Ok(20)));
//! assert!(iterator.next().unwrap().is_err());
//! assert_eq!(iterator.next(), Some(Ok(30)));
//! assert_eq!(iterator.next(), None);
//! ```

mod box_ok;
mod map_ok;

pub use box_ok::{BoxOk, BoxingFn};
pub use map_ok::{MapOk, MapOkIter};

/// Commonly used imports.
pub mod prelude {
    pub use crate::{BoxOk, BoxingFn};
    pub use crate::{MapOk, MapOkIter};
}