INNER CODE UNIT · Rust
test
stepancheg/rust-protobuf · protobuf-examples/customize-serde/src/lib.rs:85
fn test() {
let mut fruit = Fruit::new();
fruit.set_name("Orange".to_owned());
fruit.set_weight(1.5);
fruit.set_shape(Shape::CIRCLE);
// Serde works.
// Note rust-protobuf has built in support for JSON,
// which follows protobuf-JSON serialization more correctly than default serde-json.
// This example here is for the demonstration of generation of custom derives.
let json = serde_json::to_string(&fruit).unwrap();
assert_eq!(
"{\"name\":\"Orange\",\"weight\":1.5,\"shape\":\"CIRCLE\"}",
json
);
// TODO: add deserialization test
}