Skip to content

Allows you to use a macro prefix_all to prefix every attribute in structs and enums on serialization

License

Notifications You must be signed in to change notification settings

jonathan-s/serde-prefix

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Latest Version

Serde Prefix

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.

Usage

#[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 :).

About

Allows you to use a macro prefix_all to prefix every attribute in structs and enums on serialization

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages