cdumay_result

Crates.iocdumay_result
lib.rscdumay_result
version0.3.0
sourcesrc
created_at2024-06-21 09:55:03.761706
updated_at2024-07-05 06:58:58.298599
descriptionA library to serialize and deserialize result using serde
homepagehttps://github.com/cdumay/rust-cdumay_result
repositoryhttps://github.com/cdumay/rust-cdumay_result
max_upload_size
id1279342
size15,617
Cédric Dumay (cdumay)

documentation

https://docs.rs/cdumay_result

README

cdumay_result License: BSD-3-Clause cdumay_result on crates.io cdumay_result on docs.rs Source Code Repository

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"
  }
}
Commit count: 38

cargo fmt