serde-prefix-all

Crates.ioserde-prefix-all
lib.rsserde-prefix-all
version0.1.0
created_at2025-06-29 16:12:21.887547+00
updated_at2025-06-29 16:12:21.887547+00
descriptionAttribute macro to add a prefix to all struct fields & enum variants
homepage
repositoryhttps://github.com/zeenix/serde-prefix-all
max_upload_size
id1730884
size20,629
Zeeshan Ali Khan (zeenix)

documentation

README

Build Status API Documentation crates.io

serde-prefix-all

Serde Prefix All

A small extension to serde that will allow you to use the macro #[prefix_all("myprefix_"). The macro will prefix each field in a struct or variant in an enum in the serialized format, with the prefix of your choice.

Behind the doors it's using #[serde(rename = "...")] to rename each field/variant with the prefix defined in prefix_all.

Usage

use serde::{Serialize, Deserialize};
use serde_prefix_all::prefix_all;

#[prefix_all("test_")]
#[derive(Serialize, Deserialize, Debug, PartialEq)]
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);
let deserialized: Point = serde_json::from_str(json).unwrap();
assert_eq!(point, deserialized);

Background

This is a fork of serde-prefix. The serde-prefix crate was unmaintained for years and this fork is a continuation of the work started by jonathan-s.

Commit count: 0

cargo fmt