cba/lib.rs
1//! A collection of utilities which wrap common tasks needed in cli utilities
2//! Results/Options are downgraded to Options/bools by handling errors within the wrappers using [`bog`].
3//!
4//! # Error handling strategies:
5//! ### Macros
6//! Unwrap errors from Result/Option with (get/unwrap_or) and immediately return
7//! ### BogOkExt
8//! Downgrade errors to options by bogging the error
9//! ### BogUnwrapExt
10//! Unwrap infallible errors or bog and exit process
11//! ### Misc
12//! A prefix can be added to the error with prefix_err
13//!
14//!
15//! # Additional
16//! These functions are mostly not composable
17
18pub mod bath; // Path manipulation
19pub mod bo; // File read/write
20
21pub mod broc;
22pub mod bs; // Filesystem check/set/read
23
24pub mod baccarat;
25pub mod bait;
26pub mod bother;
27pub mod bum; // macro
28
29#[cfg(feature = "bring")]
30pub mod bring;
31
32#[cfg(feature = "serde")]
33pub mod bird;
34#[cfg(feature = "serde")]
35pub use crate::bird as serde;
36
37pub mod bog;
38pub use bog::BOGGER;
39
40use std::fmt;
41#[derive(Debug, PartialEq, Eq)]
42pub struct StringError(pub String);
43
44impl fmt::Display for StringError {
45 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
46 f.write_str(&self.0)
47 }
48}
49
50impl std::error::Error for StringError {}
51
52// cannot use T: Display bound unless specialization ig
53impl<T: Into<String>> From<T> for StringError {
54 fn from(s: T) -> Self {
55 StringError(s.into())
56 }
57}