Crates.io | cdumay_result |
lib.rs | cdumay_result |
version | 0.3.0 |
source | src |
created_at | 2024-06-21 09:55:03.761706 |
updated_at | 2024-07-05 06:58:58.298599 |
description | A library to serialize and deserialize result using serde |
homepage | https://github.com/cdumay/rust-cdumay_result |
repository | https://github.com/cdumay/rust-cdumay_result |
max_upload_size | |
id | 1279342 |
size | 15,617 |
cdumay_result is a basic library used to standardize result and serialize them using serde.
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"
}
}