tracing
tracing copied to clipboard
Integration With Anyhow
Feature Request
Motivation
Reduce noise in the code
Proposal
The code would look cleaner if I could write like this:
use std::str::FromStr;
use anyhow::Context;
use num::BigUint;
use num::ToPrimitive;
use tracing::error;
fn main() {
let uint = BigUint::from_str("1").unwrap();
let floating_uint = uint
.to_f64()
.error("Failed to convert `BigUint` to `f64`.") // diff
.ok()
.unwrap();
}
Doesn't have to be called error
. Some other suggestions are tracing_error
, t_error
, tracing_err
. And same thing for the other log levels (info, warn, trace, etc)
Alternatives
Here is how I'm currently writing the code:
use std::str::FromStr;
use anyhow::Context;
use num::BigUint;
use num::ToPrimitive;
use tracing::error;
fn main() {
let uint = BigUint::from_str("1").unwrap();
let floating_uint = uint
.to_f64()
.context("Failed to convert `BigUint` to `f64`.") // diff
.map_err(|err| error!("{err}")) // diff
.ok()
.unwrap();
}