Expand description
Simple diagnostics utilities for Rust — part of the cross-language Diagnosticism family.
Diagnosticism offers small, focused helpers that extend the standard library for logging, profiling, and debug output. The project is implemented in several languages; each port exposes facilities that are useful and idiomatic in that environment. (See Diagnosticism.Python for a wider API, including tracing and callstack capture.)
In Rust, this crate focuses on three areas:
Debughelpers — control what appears in log output (Ellipsis,Password,DebugSqueezer);- Timing — record duration distributions (
DoomGram), measure closures (doom_scope), and format durations viananoseconds_to_stringintoNanosecondsStr; - Source location — compile-time file, line, and function
macros (
fileline!,filelinefunction!, and others).
For example, Ellipsis in a custom Debug
implementation can elide fields in terse "{:?}" output while
still including them in alternate "{:#?}" form.
§Installation
Reference in Cargo.toml in the usual way:
diagnosticism = { version = "0" }§Components
§Types and functions
The following are re-exported at the crate root (and also available in
diagnostics):
DebugSqueezer— restrict the length ofDebugoutput for individual fields;DoomGram— decimal order-of-magnitude histogram with a compact 12-character strip for logging, plusDoomGram::to_mmmandDoomGram::to_nmmmmin/mean/max duration summaries;Ellipsis— emit"..."for redactedDebugfields;Password— emit a run of*characters for sensitiveDebugfields;doom_scope— time a closure and record the elapsed duration in aDoomGram;NanosecondsStr— compact storage for a formatted duration string;nanoseconds_to_string— format a nanosecond count into aNanosecondsStr;
§Macros (crate root)
File, line, and function helpers are exported at the crate root:
fileline!— file name and line number at the call site;filelinefunction!— file, line, and unqualified function name;filelinefunction_fully_qualified_name!— file, line, and fully-qualified function name;function_fully_qualified_name!— fully-qualified name of the enclosing function;function_name_only!— unqualified name of the enclosing function;type_name_only!— unqualified name of a given type;
§Redacting Debug fields
Both Ellipsis and Password are field placeholders in custom
Debug implementations; neither reads the underlying
value.
Ellipsis—"..."for verbose, non-sensitive elision; often used with{:#?}alternate output;Password— a masked*run for sensitive values; usePassword::newfor width;
§Examples
use diagnosticism::Ellipsis;
println!("redacted: {:?}", Ellipsis::default());Further examples are provided in the repository examples directory and in the project README.
Re-exports§
pub use diagnostics::doom_scope;pub use diagnostics::nanoseconds_to_string;pub use diagnostics::DebugSqueezer;pub use diagnostics::DoomGram;pub use diagnostics::Ellipsis;pub use diagnostics::NanosecondsStr;pub use diagnostics::Password;
Modules§
Macros§
- fileline
- Expands to the file name and line number in which it was invoked.
- filelinefunction
- Expands to the file name and line number and function name in which it was invoked.
- filelinefunction_
fully_ qualified_ name - Expands to the file name, line number, and fully-qualified function name at the call site.
- function_
fully_ qualified_ name - Expands to the fully-qualified name of the function in which it was invoked.
- function_
name_ only - Expands to the unqualified name of the function in which it was invoked.
- type_
name_ only - Expands to the unqualified
std::any::type_nameof the given type.