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: Seecli. Note that logging is still available without any feature flag.coroutineandcoroutine-heavy: Enablesasyncand integration withtokio. Seecu::co.fs: Enables file system utils. Seecu::fsandcu::bin.process: Enables utils spawning child process. See [Command].parse,json,yaml,toml: Enable parsing utilities, and additional support for common formats. SeeParse.
Modules§
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-
anyhowerror 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
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
- 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§
- Boxed
Future - Alias for a boxed future
- Result
Result<T, Error>
Attribute Macros§
- error_
ctx - Attribute macro for wrapping a function with an error context