config-diag

Crates.ioconfig-diag
lib.rsconfig-diag
version1.0.2
sourcesrc
created_at2021-06-21 10:55:46.460271
updated_at2022-09-01 09:56:06.455598
descriptionProvide a .diag() function for diagnostic output if requested.
homepage
repositoryhttps://gitlab.com/ppentchev/config-diag-rs
max_upload_size
id412819
size10,162
Peter Pentchev (ppentchev)

documentation

README

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(())
}
Commit count: 27

cargo fmt