Skip to main content

rumtk_serialize

Macro rumtk_serialize 

Source
macro_rules! rumtk_serialize {
    ( $object:expr ) => { ... };
    ( $object:expr, $pretty:expr ) => { ... };
}
Expand description

Serialization macro which will take an object instance decorated with [Serialize] trait from serde and return the JSON string representation.

You can pass up to two parameters. The first parameter is the serializable object instance. The second parameter is a boolean indicating whether to pretty print. Omit the second parameter if not debugging to save on bytes transferred around.

§Examples

§Pretty Print

use rumtk_core::json::serialization::{RUMSerialize};
use rumtk_core::strings::RUMString;
use rumtk_core::rumtk_serialize;

#[derive(RUMSerialize)]
struct MyStruct {
    hello: RUMString
}

let hw = MyStruct{hello: RUMString::from("World")};
let hw_str = rumtk_serialize!(&hw, true).unwrap();

assert!(hw_str.len() > 0, "Empty JSON string generated from the test struct!");

§Default

use rumtk_core::json::serialization::{RUMSerialize};
use rumtk_core::strings::RUMString;
use rumtk_core::rumtk_serialize;

#[derive(RUMSerialize)]
struct MyStruct {
    hello: RUMString
}

let hw = MyStruct{hello: RUMString::from("World")};
let hw_str = rumtk_serialize!(&hw).unwrap();

assert!(hw_str.len() > 0, "Empty JSON string generated from the test struct!");