Expand description
A personal utility crate.
Adds reexports of snafu, new piping traits (Pipe, Inspect, Lay), and reexports tracing + tracing_subscriber (as tracing_utils::subscriber) with a prelude and quick init function.
Snafu’s Whatever type is reexported as R = Result<T, Whatever>, and the R<()> is reexported as U. Use cew::e!() to call snafu::whatever!() and cew::me!() to call Err(snafu::whatever!()).
The Pipe, Inspect, and Lay traits provide functions to reduce the amount of stacked parenthesis in long method chains, like the tap crate.
The tracing_subscriber quick init should be overriden with a custom impl if needed, but it gets you started quickly.
Usage:
use cew::prelude::*;
fn main() -> cew::U {
cew::tracing::init_filtered_w_env(
cew::tracing::fmt_layer().without_time(),
// What should the default level be if the environment variable is not set?
"info,verbose_crate=warn"
).whatever_context("Failed to initialise tracing")?;
info!("Traced").
cew::me!("Error")
}Re-exports§
pub use snafu;
Modules§
Macros§
Structs§
- Whatever
- A basic error type that you can use as a first step to better error handling.
Traits§
- Inspect
- Run a function on a shared reference to self, but return self.
Use the fallible/nullable functions [
inspect_try] and [inspect_maybe] if you want to propagate errors. - Lay
- Run a function that mutates self, returning self.
Use the fallible/nullable functions [
lay_try] and [lay_maybe] if you want to propagate errors. - Option
Ext - Additions to
Option. - Pipe
- Apply a transformation to self, returning the result.
- Result
Ext - Additions to
Result.
Type Aliases§
Derive Macros§
- Snafu
- The
Snafumacro is the entrypoint to defining your own error types. It is designed to require little configuration for the recommended and typical usecases while still offering flexibility for unique situations.