config-diag 1.0.2

Provide a .diag() function for diagnostic output if requested.
Documentation
  • Coverage
  • 100%
    6 out of 6 items documented1 out of 6 items with examples
  • Size
  • Source code size: 9.83 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.1 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 9s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • ppentchev/config-diag-rs
    0 1 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • ppentchev

config-diag -- provide a .diag() function for diagnostic output if requested

The ConfigDiag trait may be used to decorate an object that stores some kind of configuration information. It adds a diag method that checks whether verbose output has been requested and, if so, displays a message to the standard error stream. If the diag_to_stderr method is overridden and it returns false, any diagnostic messages selected for display are sent to the standard output stream instead.

Example:

use std::error;

use config_diag::ConfigDiag;

struct Config {
    verbose: bool,
}

impl ConfigDiag for Config {
    fn diag_is_verbose(&self) -> bool {
        self.verbose
    }
}

pub fn main() -> Result<(), Box<dyn error::Error>> {
    let config = Config { verbose: true };
    let event = 42;
    config.diag(|| format!("Something happened: {}", event));
    config.diag_("Got here!");
    Ok(())
}