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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//! # vivian's essential utilities
//!
//! Some nifty utilities to make some mostly-already-easy tasks easier.
//!
//! ## Installation
//!
//! `Cargo.toml`:
//!
//! ```toml
//! [dependencies]
//! vivian-essentials = "0.1"
//! ```
//!
//! ## API
//!
//! Read the docs for all the functionality.
//!
//! ### guard
//!
//! Guard against something that should be true, returning an error if it's not:
//!
//! ```rust
//! # fn some_condition() -> bool { true }
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! essentials::guard(some_condition())?;
//! # Ok(()) }
//! ```
//!
//! This is useful for `?` heavy code, and is especially useful with crates like
//! `snafu`:
//!
//! ```rust,ignore
//! use crate::error::UserNotVerified;
//! use snafu::ResultExt;
//!
//! essentials::guard(user.is_verified()).context(UserNotVerified)?
//! ```
//!
//! ### io
//!
//! Prompt a user for something with a message:
//!
//! ```rust,no_run
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let email = essentials::prompt("What is your email address?\n> ")?;
//! # Ok(()) }
//! ```
//!
//! ### sugar
//!
//! If you miss ternaries, then this is one of the closest ways you can get without
//! using a macro:
//!
//! ```rust
//! # #[derive(Debug, Eq, PartialEq)] enum Discount { Regular, Senior }
//! # let age = 50i32;
//! let discount = essentials::tern(age > 65, Discount::Senior, Discount::Regular);
//! # assert_eq!(Discount::Regular, discount);
//! ```
//!
//! ## License
//!
//! ISC.

pub mod guard;
pub mod io;
pub mod prelude;
pub mod sugar;

pub use guard::guard;
pub use io::prompt;
pub use sugar::tern;