3 unstable releases
0.3.0 | Jul 5, 2024 |
---|---|
0.2.1 | Jun 21, 2024 |
0.2.0 | Jun 21, 2024 |
#777 in Encoding
25 downloads per month
Used in 3 crates
11KB
173 lines
cdumay_error
cdumay_error is a basic library used to standardize errors and serialize them using serde.
Quickstart
Cargo.toml:
[dependencies]
cdumay_error = "0.3"
serde_json = "1.0"
main.rs:
extern crate cdumay_error;
extern crate serde_json;
use cdumay_error::{ErrorBuilder, GenericErrors, JsonError};
use std::collections::BTreeMap;
use serde_json::Value;
fn main() {
let err = ErrorBuilder::from(GenericErrors::GENERIC_ERROR)
.message("This is a useless generic error.".to_string())
.extra({
let mut extra = BTreeMap::new();
extra.insert("context".into(), Value::String("Example".to_string()));
extra
})
.build();
println!("{}", serde_json::to_string_pretty(&JsonError::from(err)).unwrap());
}
Output:
{
"code": 500,
"extra": {
"context": "Example"
},
"message": "This is a useless generic error.",
"msgid": "Err-15452"
}
Dependencies
~0.7–1.6MB
~34K SLoC