Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jonathan-s/serde-prefix
Allows you to use a macro prefix_all to prefix every attribute in structs and enums on serialization
https://github.com/jonathan-s/serde-prefix
rust serde
Last synced: 3 months ago
JSON representation
Allows you to use a macro prefix_all to prefix every attribute in structs and enums on serialization
- Host: GitHub
- URL: https://github.com/jonathan-s/serde-prefix
- Owner: jonathan-s
- License: mit
- Created: 2019-06-20T12:56:57.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-03-28T08:54:19.000Z (almost 4 years ago)
- Last Synced: 2024-10-12T07:34:50.516Z (3 months ago)
- Topics: rust, serde
- Language: Rust
- Size: 8.79 KB
- Stars: 12
- Watchers: 3
- Forks: 3
- Open Issues: 4
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
[![Build Status]][travis] [![Latest Version]][crates.io]
[Build Status]: https://travis-ci.org/jonathan-s/serde-prefix.svg?branch=master
[travis]: https://travis-ci.org/jonathan-s/serde-prefix[Latest Version]: https://img.shields.io/crates/v/serde_prefix.svg
[crates.io]: https://crates.io/crates/serde_prefix# 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
```rust
#[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 :).