Diagnosticism, for Rust
Diagnosticism is a library providing miscellaneous discrete and simple diagnostics facilities to supplement what is available in the standard library. It implemented in several languages, providing enhancements that are necessary (and possible). For example, Diagnosticism.Python can provide the trace()
function that can capture the callstack information to issue into a diagnostic log statement.
In Rust, which has many powerful reflective and diagnostic elements built in, the facilities are (currently) aimed around supplementing the std::fmt::Debug
trait. For example, the Ellipsis
component is able to be used in a custom Debug
implementation for a given type to elide certain aspects of the instance's state that is not of interest in the logs or, perhaps, to elide with "{:?}"
but still include in "{:#?}"
(the #alternate()
form). (See the Examples section below for more on this.)
Other facilities (that are not directly related to Debug
) will be added to the crate soon (and will be listed in the Components section below).
Reference in Cargo.toml in the usual way:
diagnosticism = { version = "0" }
No public constants are defined at this time.
No public enumerations are defined at this time.
No public crate-specific features are defined at this time.
No public functions are defined at this time.
No public macros are defined at this time.
The following structures are defined:
DebugSqueezer
- used to assist with restricting the length ofDebug
forms of fields within a given width;Ellipsis
- provides strings such as"********"
to be used for fields that are sensitive and whoseDebug
forms are not to be expressed;Password
- Simple type that provides the string"..."
to be used for fields whoseDebug
forms are not to be expressed;
No public traits are defined at this time.
In the example program ellipsis (in examples directory), the following types are defined to illustrate the benefit of using Ellipsis
to provide concise Debug
output in terse (i.e. non-#alternate()
) form:
/// Large structure that provides the internals of `Thing`
#[derive(Clone)]
#[derive(Debug)]
struct LargeInternal {
f1 : i64,
f2 : f32,
f3 : BTreeMap<&'static str, &'static str>,
f4 : BTreeSet<u64>,
f5 : Vec<HashMap<BTreeMap<i32, String>, BTreeSet<u64>>>,
}
#[derive(Debug)]
struct Thing1 {
name : String,
internals : Option<LargeInternal>,
}
struct Thing2 {
name : String,
internals : Option<LargeInternal>,
}
impl std::fmt::Debug for Thing2 {
fn fmt(
&self,
f: &mut std::fmt::Formatter<'_>,
) -> std::fmt::Result {
if f.alternate() {
f
.debug_struct("Thing2")
.field("name", &self.name)
.field("internals", &self.internals)
.finish()
} else {
let ellipsis = Ellipsis::default();
f
.debug_struct("Thing2")
.field("name", &self.name)
.field("internals", &ellipsis)
.finish()
}
}
}
and the program's output illustrates these differing forms, as shown in this filtered form:
Terse `Debug` form of `thing1`: Thing1 { name: "i-am-a-public-thing", internals: Some(LargeInternal { f1: -123, f2: -3.4028235e38, f3: {"a": "A", "b": "B", "c": "C", "d": "D", "e": "E", "f": "F"}, f4: {1, 2, 4, 11, 12345678}, f5: [] }) }
Terse `Debug` form of `thing2`: Thing2 { name: "i-am-a-public-thing", internals: ... }
Defect reports, feature requests, and pull requests are welcome on https://github.com/synesissoftware/Diagnosticism.Rust.
Diagnosticism.Rust has no (non-development) dependencies.
Crates upon which Diagnosticism.Rust has development dependencies:
Diagnosticism.Rust is released under the 3-clause BSD license. See LICENSE for details.