Crate pistonite_cu

Crate pistonite_cu 

Source
Expand description

Batteries-included common utils

(If you are viewing this on docs.rs, please use the self-hosted version instead)

§Install

Since crates.io does not have namespaces, this crate has a prefix. You should manually rename it to cu, as that’s what the proc-macros expect.

# Cargo.toml
# ...
[dependencies.cu]
package = "pistonite-cu"
version = "..." # check by running `cargo info pistonite-cu`
features = [ "full" ] # see docs

# ...
[dependencies]

§General Principal

cu tries to be as short as possible with imports. Common and misc utilities are exported directly by the crate and should be used as cu::xxx directly. Sub-functionalities are bundled when makes sense, and should be called from submodules directly, like cu::fs::xxx or cu::co::xxx. The submodules are usually 2-4 characters.

The only time to use use to import from cu, is with the prelude module pre:

use cu::pre::*;

This imports traits like Context and [PathExtension] into scope.

§Feature Reference:

  • cli, print, prompt: See cli. Note that logging is still available without any feature flag.
  • coroutine and coroutine-heavy: Enables async and integration with tokio. See cu::co.
  • fs: Enables file system utils. See cu::fs and cu::bin.
  • process: Enables utils spawning child process. See [Command].
  • parse, json, yaml, toml: Enable parsing utilities, and additional support for common formats. See Parse.

Modules§

lib
Lib re-exports
lv
Printing level values
pre
Prelude imports

Macros§

bail
Return early with an error.
bailand
Invoke a print macro, then bail with the same message
bailfyi
Return an error, expecting the error will eventually be propagated as a fatal error to the user, as an FYI.
check
Check a Result, unwrapping the value or giving it a context and return the error.
debug
Logs a message at the debug level.
ensure
Return early with an error if a condition is not satisfied.
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.
noimpl
Like unimplemented! in std library, but log a message and return an error instead of panicking
panicand
Invoke a print macro, then panic with the same message
rethrow
Rethrow an Err, optionally with additional context
trace
Logs a message at the trace level.
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
color_enabled
Get if color printing is enabled
copy
Copy a reader to a writer.
disable_print_time
Disable printing the time took to run the command
disable_trace_hint
Disable printing the trace hint line if the CLI entry point returns an error
env_var
Like std::env::var, but treat not-set as empty string. Tracing and reporting is built-in.
log_enabled
Check if the logging level is enabled

Type Aliases§

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

Attribute Macros§

error_ctx
Attribute macro for wrapping a function with an error context