Git Product home page Git Product logo

serde-prefix's Introduction

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

serde-prefix's People

Contributors

jonathan-s avatar

Stargazers

Anne Thorpe avatar Jackson avatar Praveen Perera avatar Artur Sinila avatar Alexander Irbis avatar Stanislav Tkach avatar Andrejs Agejevs avatar David Ed Mellum avatar Jonathan McHugh avatar Sharad Chand avatar  avatar laserx avatar

Watchers

James Cloos avatar David Tolnay avatar  avatar

serde-prefix's Issues

Support for suffix

I have a collection of tagged enums that are represented with enum_type, struct_type, etc. in the serialized form, and I want to deserialize them into an enum Type { Enum, Struct, ... }.

For that, I need a suffix version of the renaming rule - would it make sense to add it to the same crate?

Support rename_all rule

Currently, there is no way to combine prefix with serde(rename_all = ...). I think it should be possible for serde-prefix to look up the rename_all atrribute and combine its rules with the prefix one.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.