essentials/lib.rs
1//! # vivian's essential utilities
2//!
3//! Some nifty utilities to make some mostly-already-easy tasks easier.
4//!
5//! ## Installation
6//!
7//! `Cargo.toml`:
8//!
9//! ```toml
10//! [dependencies]
11//! vivian-essentials = "0.1"
12//! ```
13//!
14//! ## API
15//!
16//! Read the docs for all the functionality.
17//!
18//! ### guard
19//!
20//! Guard against something that should be true, returning an error if it's not:
21//!
22//! ```rust
23//! # fn some_condition() -> bool { true }
24//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
25//! essentials::guard(some_condition())?;
26//! # Ok(()) }
27//! ```
28//!
29//! This is useful for `?` heavy code, and is especially useful with crates like
30//! `snafu`:
31//!
32//! ```rust,ignore
33//! use crate::error::UserNotVerified;
34//! use snafu::ResultExt;
35//!
36//! essentials::guard(user.is_verified()).context(UserNotVerified)?
37//! ```
38//!
39//! ### io
40//!
41//! Prompt a user for something with a message:
42//!
43//! ```rust,no_run
44//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
45//! let email = essentials::prompt("What is your email address?\n> ")?;
46//! # Ok(()) }
47//! ```
48//!
49//! ### sugar
50//!
51//! If you miss ternaries, then this is one of the closest ways you can get without
52//! using a macro:
53//!
54//! ```rust
55//! # #[derive(Debug, Eq, PartialEq)] enum Discount { Regular, Senior }
56//! # let age = 50i32;
57//! let discount = essentials::tern(age > 65, Discount::Senior, Discount::Regular);
58//! # assert_eq!(Discount::Regular, discount);
59//! ```
60//!
61//! ## License
62//!
63//! ISC.
64
65pub mod guard;
66pub mod io;
67pub mod prelude;
68pub mod sugar;
69
70pub use guard::guard;
71pub use io::prompt;
72pub use sugar::tern;