Last active
August 23, 2020 12:42
-
-
Save yutakahashi114/3d208f532179b074d78be444a4a56b06 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate rust_map_macro; | |
use rust_map_macro::mapper::{Mapper, Time}; | |
use std::collections::HashMap; | |
#[macro_use] | |
extern crate mapper_derive; | |
fn main() { | |
let test = Test { | |
null: None, | |
boolean: true, | |
int: 1234, | |
float: 56.78, | |
string: "str".to_string(), | |
array: vec!["array1".to_string(), "array2".to_string()], | |
map: vec![("seconds".to_string(), 1234), ("nanos".to_string(), 5678)] | |
.into_iter() | |
.collect(), | |
time: Time { | |
seconds: 1234, | |
nanos: 5678, | |
}, | |
}; | |
let test_map = test.to_map(); | |
println!("map"); | |
println!("{:?}", test_map); | |
let test = Test::from_map(test_map).unwrap(); | |
println!("struct"); | |
println!("{:?}", test); | |
} | |
#[derive(Debug, Mapper)] | |
struct Test { | |
null: Option<String>, | |
boolean: bool, | |
int: i64, | |
float: f64, | |
string: String, | |
array: Vec<String>, | |
map: HashMap<String, i64>, | |
time: Time, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment