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
//! A bunch of patterns that I often met while programming in Rust. I put them
//! in a single crate, so other Rustaceans may also enjoy them.
//!
//! This crate has the following goals:
//!   - as lightweight as possible, no dependencies,
//!   - integrate patterns with each others.
//!
//! # Current patterns
//!
//! ### `apply`
//!
//! Some methods in Rust don't take ownership, and just take reference of an
//! object. This may be nice in some situations, but this does not allow to
//! chain methods. The `Apply` trait allows to bring back method chaining for
//! methods which take mutable references.
//!
//! For example, `HashMap` can be created easily:
//!
//! ```rust
//! use std::collections::HashMap;
//!
//! use shpat::prelude::*;
//!
//! let map = HashMap::new()
//!     .apply(|m| m.insert("manatee", 42))
//!     .apply(|m| m.insert("horse", 101));
//! ```
//!
//! The `Apply` trait is implemented for every `Sized` type. It also provides
//! `apply_keep`, which returns the value returned by the inner method and the
//! object itself (which may be usefull when one wants to insert a value in a
//! hash map, but want to keep returned value), and `apply_unwrap`, which will
//! call `unwrap` on every `Unwrapable` returned value.
//!
//! ## `Unwrappable`
//!
//! The `Unwrappable` trait is an attempt to unify the behavior of types which
//! represent a success or failure dichotomy, such as `Result` and `Option`.
//! These type implement a method which returns the success value, and panics
//! if it was a failure. These behaviours are unified with the `unwrap`
//! function.
//!
//! This trait is implemented for both `Result` and `Option`. It is closely
//! related to the `Try` trait from the standard library.

#![forbid(missing_docs)]
#![forbid(clippy::missing_docs_in_private_items)]
#![forbid(clippy::missing_errors_doc)]

mod apply;
mod unwrappable;

pub mod prelude;