-
Notifications
You must be signed in to change notification settings - Fork 1
Usage
Nicolas edited this page Nov 15, 2023
·
2 revisions
Usage:
The basic use of the log crate is through the five logging macros:error!
,warn!
,info!
,debug!
andtrace!
whereerror!
represents the highest-priority log messages andtrace!
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!.
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)