2 unstable releases
0.3.0 | Jul 5, 2024 |
---|---|
0.2.0 | Jun 21, 2024 |
#1135 in Encoding
21 downloads per month
Used in 2 crates
(via cdumay_http_client)
14KB
264 lines
cdumay_result
cdumay_result is a basic library used to standardize result and serialize them using serde.
Quickstart
Cargo.toml:
[dependencies]
cdumay_result = "0.3"
serde_json = "1.0"
main.rs:
extern crate cdumay_result;
extern crate serde_json;
use cdumay_result::{ResultBuilder, JsonResult};
use std::collections::BTreeMap;
use serde_json::Value;
fn main() {
let result = ResultBuilder::default()
.stdout("A useful result !".into())
.retval({
let mut values = BTreeMap::new();
values.insert("Hello".into(), Value::String("World".into()));
values
})
.build();
println!("{}", serde_json::to_string_pretty(&JsonResult::from(result)).unwrap());
}
Output:
{
"uuid": "166d5744-b159-48b5-b8c6-9242abd8ebfb",
"retcode": 0,
"stdout": "A useful result !",
"retval": {
"Hello": "World"
}
}
Dependencies
~1–1.8MB
~38K SLoC