Expand description
§Cu = Copper
Batteries-included common utils
(If you are viewing this on docs.rs, please use the self-hosted version instead)
§Quick start
When installing, rename the crate to cu in Cargo.toml:
# Cargo.toml
# ...
[dependencies.cu]
package = "pistonite-cu"
version = "..." # check by running `cargo info pistonite-cu`
features = [ "full" ] # see docs
[dependencies]
# ...The goal with using cu is use only one use statement:
use cu::pre::*;This brings into scope a few things:
- Traits that are expected to be used, such as
anyhow::Context - Re-exports of modules, such as
jsonif thejsonfeature is enabled
If a function or type is not included with pre::*, that means the canonical
style for using it is with the full path, for example, you would write:
ⓘ
use cu::pre::*;
fn read_file() -> cu::Result<()> {
cu::fs::read_string("foo/bar.txt")?;
cu::info!("successfully read file");
Ok(())
}instead of the below:
ⓘ
use cu::pre::*;
use cu::{Result, fs, info};
// ^ don't include extra uses!
// the biggest disadvantage of this is
// it's easy to confuse with types in the standard library
fn read_file() -> Result<()> {
fs::read_string("foo/bar.txt")?;
info!("successfully read file");
Ok(())
}§Quick Reference
- Error Handling (via
anyhow) - Logging (via
log) - Printing and Command Line Interface (CLI arg parsing via
clap) - Handling Ctrl-C
- Progress Bars
- Prompting
- Coroutines (Async) (via
tokio) - File System Paths and Strings
- File System Operations
- Binary Path Registry
- Spawning Child Processes
- Parsing (via
serde) - Derive Macros: the
derivefeature, viaderive_more
Re-exports§
pub use str::ByteFormat;pub use str::ZString;
Modules§
Macros§
- bail
- Return early with an error.
- check
- Error Handling
- debug
- Logs a message at the debug level.
- ensure
- Check if an expression is
true - error
- Logs a message at the error level.
- fmtand
- Format and invoke a print macro
- fmterr
- Construct an ad-hoc error from a string or existing non-
anyhowerror value. - info
- Logs a message at the info level.
- panicand
- Invoke a print macro, then panic with the same message
- rethrow
- Rethrow an
Err, optionally with additional context - some
- Check if an expression is
Some - trace
- Logs a message at the trace level.
- unimplemented
- Like
unimplemented!in std library, but log a message and return an error instead of panicking - unreachable
- Like
unreachable!in std library, but log a message and return an error instead of panicking reached. This might be less performant in release builds - warn
- Logs a message at the warn level.
Structs§
- Atomic
- An atomic wrapper with an underlying atomic storage and conversion to a type T.
- Error
- The
Errortype, a wrapper around a dynamic error type.
Traits§
- Atomic
Type - Marker type to associate primitive with their atomic versions
- Context
- Provides the
contextmethod forResult.
Functions§
- Ok
- Equivalent to
Ok::<_, anyhow::Error>(value). - best_
effort_ panic_ info - Try to get info from a panic payload
- copy
- Copy a reader to a writer.
- env_var
- Like
std::env::var, but treat not-set as empty string. Tracing and reporting is built-in.
Type Aliases§
- Boxed
Future - Alias for a boxed future
- Result
Result<T, Error>
Attribute Macros§
- context
- Attribute macro for wrapping a function with an error context