Skip to content
Nicolas edited this page Nov 15, 2023 · 2 revisions

log

https://crates.io/crates/log

Usage:
The basic use of the log crate is through the five logging macros: error!, warn!, info!, debug! and trace! where error! represents the highest-priority log messages and trace! the lowest. The log messages are filtered by configuring the log level to exclude messages with a lower priority. Each of these macros accept format strings similarly to println!.

anyhow

https://crates.io/crates/anyhow

Usage:
This library provides anyhow::Error, a trait object based error type for easy idiomatic error handling in Rust applications.

Example:

use anyhow::Context;

fn test() -> anyhow::Result<()> {
    // watch out for the question mark operator

    let file = std::fs::File::create("test.txt").context("Failed to create test file")?;

    file.set_len(1234).context("Failed to set file length")?;

    Ok(())
}

If this fails the result is a fancy error message:

Error: Failed to create test file

Caused by:
    File exists (os error 17)
Clone this wiki locally