Skip to main content

Crate pistonite_cu

Crate pistonite_cu 

Source
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 json if the json feature 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

Re-exports§

pub use str::ByteFormat;
pub use str::ZString;

Modules§

lv
Logging
str
Working with bytes

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-anyhow error 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 Error type, a wrapper around a dynamic error type.

Traits§

AtomicType
Marker type to associate primitive with their atomic versions
Context
Provides the context method for Result.

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§

BoxedFuture
Alias for a boxed future
Result
Result<T, Error>

Attribute Macros§

context
Attribute macro for wrapping a function with an error context