3 releases
Uses old Rust 2015
0.1.2 | Oct 22, 2018 |
---|---|
0.1.1 | Oct 21, 2018 |
0.1.0 | Oct 20, 2018 |
#471 in #structure
Used in json_in_type
8KB
132 lines
Procedural macros for json_in_type
This crate defines a derive mode macro allowing the automatic derivation of the JSONValue trait for custom data structures.
Example
extern crate json_in_type;
#[macro_use]
extern crate json_in_type_derive;
use json_in_type::JSONValue;
#[derive(JSONValue)]
struct MyObject { // This will be encoded as a JSON object
void: (),
list: Vec<u8>,
hello: String,
}
#[derive(JSONValue)]
struct WrapperStruct(u8, u8); // This will be encoded as a JSON list
lib.rs
:
This module provides a procedural macro to derive JSONValue for custom structs.
Examples
extern crate json_in_type;
#[macro_use] extern crate json_in_type_derive;
use json_in_type::JSONValue;
#[derive(JSONValue)]
struct MyObject {
void: (),
list: Vec<u8>,
hello: String,
}
let obj = MyObject {
void: (),
list: vec![1, 2, 3],
hello: String::from("world"),
};
assert_eq!(
r#"{"void":null,"list":[1,2,3],"hello":"world"}"#,
obj.to_json_string()
);
Dependencies
~2MB
~47K SLoC