error_combinator/lib.rs
1//! [![github]](https://github.com/Tom-game-project/error-combinator) [![crates-io]](https://crates.io/crates/error-combinator) [![docs-rs]](https://docs.rs/error-combinator/)
2//!
3//! [github]: https://img.shields.io/badge/github-8da0cb?style=for-the-badge&labelColor=555555&logo=github
4//! [crates-io]: https://img.shields.io/badge/crates.io-fc8d62?style=for-the-badge&labelColor=555555&logo=rust
5//! [docs-rs]: https://img.shields.io/badge/docs.rs-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs
6//!
7//! # Example
8//!
9//! ```
10//! use error_combinator::{
11//! check::{
12//! Check, // trait
13//! CheckOutcome, // struct
14//! CheckState // struct
15//! },
16//! };
17//!
18//! use std::marker::PhantomData;
19//!
20//! struct Checked;
21//! struct Unchecked;
22//! struct ErrState<CheckStartsWithHello> {
23//! _check_starts_with_hello: PhantomData<CheckStartsWithHello>,
24//! }
25//!
26//! #[derive(Debug)]
27//! enum ValidateErr {
28//! CheckStartsWithHelloErr,
29//! }
30//!
31//! /// function that has `Fn(CheckState<T, Pre>) -> CheckOutcome<T, State, E>` type
32//! /// be implemented `Check trait` automatically
33//! /// You can call following method.
34//! /// ```
35//! /// let r = checker.check(
36//! /// CheckState::new(s)
37//! /// );
38//! /// ```
39//! fn check_starts_with_hello(
40//! data: CheckState<&str, ErrState<Unchecked>>)
41//! ->
42//! CheckOutcome<&str, ErrState<Checked>, ValidateErr>
43//! {
44//! if data.value.starts_with("hello") {
45//! CheckOutcome::Passed(
46//! CheckState::new(data.value)
47//! )
48//! } else {
49//! CheckOutcome::Failed{
50//! state: CheckState::new(data.value),
51//! err: ValidateErr::CheckStartsWithHelloErr
52//! }
53//! }
54//! }
55//!
56//! fn main() {
57//! let s= "hello abc world";
58//! let checker = check_starts_with_hello;
59//!
60//! // call `Check` trait method
61//! let r = checker.check(
62//! CheckState::new(s)
63//! );
64//! println!("test case: \"{}\"", s);
65//! match r {
66//! CheckOutcome::Passed(_v) => {
67//! println!("Passed!");
68//! }
69//! CheckOutcome::Failed{state:_, err} => {
70//! println!("Failed because");
71//! println!("{:?}", err)
72//! }
73//! }
74//! println!("---")
75//! }
76//!
77//! ```
78
79pub mod check;
80pub mod cmberr;
81