| Crates.io | serde_prefix |
| lib.rs | serde_prefix |
| version | 0.1.0 |
| created_at | 2019-06-21 09:57:04.068214+00 |
| updated_at | 2019-06-21 09:57:04.068214+00 |
| description | A macro for usage with serde to prefix all attributes in structs and enum |
| homepage | https://github.com/jonathan-s/serde-prefix |
| repository | https://github.com/jonathan-s/serde-prefix |
| max_upload_size | |
| id | 142559 |
| size | 6,908 |
A small extension to serde that will allow you to use the macro #[prefix_all("myprefix_"). The macro will prefix each attribute in a struct or enum with the prefix of your choice.
Behind the doors it's using #[serde(rename = "...")] to rename each attribute with the prefix defined in prefix_all.
#[macro_use]
extern crate serde_prefix;
extern crate serde;
use serde::{Serialize, Deserialize};
#[prefix_all("test_")]
#[derive(Serialize, Debug)]
struct Point {
x: i32,
y: i32
}
let point = Point { x: 1, y: 2 };
let serialized = serde_json::to_string(&point).unwrap();
let json = r#"{"test_x":1,"test_y":2}"#;
assert_eq!(serialized, json);
If there is anything that you are missing create an issue :).