pistonite_cu/
lib.rs

1//! Batteries-included common utils
2//!
3//! # Install
4//! Since crates.io does not have namespaces, this crate has a prefix.
5//! You should manually rename it to `cu`, as that's what the proc-macros
6//! expect.
7//! ```toml
8//! # Cargo.toml
9//! # ...
10//! [dependencies.cu]
11//! package = "pistonite-cu"
12//! version = "..." # check by running `cargo info pistonite-cu`
13//! features = [ "full" ] # see docs
14//!
15//! # ...
16//! [dependencies]
17//! ```
18//!
19//! # General Principal
20//! `cu` tries to be as short as possible with imports. Common and misc
21//! utilities are exported directly by the crate and should be used
22//! as `cu::xxx` directly. Sub-functionalities are bundled when makes
23//! sense, and should be called from submodules directly, like `cu::fs::xxx`
24//! or `cu::co::xxx`. The submodules are usually 2-4 characters.
25//!
26//! The only time to use `use` to import from `cu`, is with the prelude module
27//! `pre`:
28//! ```rust
29//! # use pistonite_cu as cu;
30//! use cu::pre::*;
31//! ```
32//! This imports traits like [`Context`] and [`PathExtension`] into scope.
33//!
34//! # Feature Reference:
35//! - `cli`, `print`, `prompt`:
36//!   See [`cli`](module@cli). Note that logging is still available without any feature flag.
37//! - `coroutine` and `coroutine-heavy`:
38//!   Enables `async` and integration with `tokio`. See [`cu::co`](module@co).
39//! - `fs`: Enables file system utils. See [`cu::fs`](module@fs) and [`cu::bin`](module@bin).
40//! - `process`: Enables utils spawning child process. See [`Command`].
41//! - `parse`, `json`, `yaml`, `toml`:
42//!   Enable parsing utilities, and additional support for common formats. See
43//!   [`Parse`](trait@Parse).
44
45#![cfg_attr(any(docsrs, feature = "nightly"), feature(doc_auto_cfg))]
46#![cfg_attr(any(docsrs, feature = "nightly"), feature(doc_cfg))]
47
48#[cfg(feature = "process")]
49mod process;
50#[cfg(feature = "process")]
51pub use process::{Child, Command, CommandBuilder, Spawn, color_flag, color_flag_eq, pio};
52#[cfg(all(feature = "process", feature = "print"))]
53pub use process::{width_flag, width_flag_eq};
54
55#[cfg(feature = "fs")]
56pub mod bin;
57#[cfg(feature = "fs")]
58#[doc(inline)]
59pub use bin::which;
60
61/// File System utils (WIP)
62#[cfg(feature = "fs")]
63pub mod fs;
64
65/// Path utils
66#[cfg(feature = "fs")]
67mod path;
68#[cfg(feature = "fs")]
69pub use path::{PathExtension, PathExtensionOwned};
70
71#[cfg(feature = "cli")]
72pub mod cli;
73#[cfg(feature = "cli")]
74pub use pistonite_cu_proc_macros::cli;
75
76mod async_;
77pub use async_::BoxedFuture;
78#[cfg(feature = "coroutine")]
79pub mod co;
80
81/// Low level printing utils and integration with log and clap
82#[cfg(feature = "print")]
83mod print;
84#[cfg(feature = "print")]
85pub use print::{
86    ProgressBar, init_print_options, log_init, progress_bar, progress_bar_lowp, progress_unbounded,
87    progress_unbounded_lowp, set_thread_print_name, term_width, term_width_height,
88    term_width_or_max,
89};
90
91/// Printing level values
92pub mod lv;
93#[doc(inline)]
94pub use lv::{color_enabled, log_enabled};
95
96/// Parsing utilities
97#[cfg(feature = "parse")]
98mod parse;
99#[cfg(feature = "parse")]
100pub use parse::*;
101#[cfg(feature = "parse")]
102pub use pistonite_cu_proc_macros::Parse;
103
104// Atomic helpers
105mod atomic;
106pub use atomic::*;
107
108// other stuff that doesn't have a place
109mod misc;
110pub use misc::*;
111
112// re-exports from libraries
113pub use anyhow::{Context, Ok, Result, anyhow as fmterr, bail, ensure};
114pub use log::{debug, error, info, trace, warn};
115#[cfg(feature = "coroutine")]
116pub use tokio::{join, try_join};
117
118#[doc(hidden)]
119pub mod __priv {
120    #[cfg(feature = "print")]
121    pub use crate::print::{__print_with_level, __prompt, __prompt_yesno};
122    #[cfg(feature = "process")]
123    pub use crate::process::__ConfigFn;
124}
125
126/// Lib re-exports
127pub mod lib {
128    #[cfg(feature = "cli")]
129    pub use clap;
130}
131
132/// Prelude imports
133pub mod pre {
134    pub use crate::Context as _;
135    #[cfg(feature = "parse")]
136    pub use crate::ParseTo as _;
137    #[cfg(feature = "fs")]
138    pub use crate::PathExtension as _;
139    #[cfg(feature = "fs")]
140    pub use crate::PathExtensionOwned as _;
141    #[cfg(feature = "process")]
142    pub use crate::Spawn as _;
143    #[cfg(feature = "json")]
144    pub use crate::json;
145    #[cfg(feature = "cli")]
146    pub use crate::lib::clap;
147    #[cfg(feature = "toml")]
148    pub use crate::toml;
149    #[cfg(feature = "yaml")]
150    pub use crate::yaml;
151    #[cfg(feature = "serde")]
152    pub use ::serde::{Deserialize, Serialize};
153}