serde_with_value_affix

Crates.ioserde_with_value_affix
lib.rsserde_with_value_affix
version0.1.0
created_at2025-01-09 14:42:04.613498+00
updated_at2025-01-09 14:42:04.613498+00
descriptionCustom affix modules for serde
homepage
repositoryhttps://github.com/Detoo/serde-with-value-affix
max_upload_size
id1509996
size22,592
(Detoo)

documentation

https://docs.rs/serde_with_value_affix

README

Serde with Value Affix

Based on serde and applies a prefix / suffix to the value of a field during serialization. Note the difference vs serde_with macros: with_prefix! and with_suffix!, which apply to each field name of a struct instead.


Installation

[dependencies]
serde_with_value_affix = "0.1.0"

Examples

Parsing JSON with suffix

use serde::{Deserialize, Serialize};
use serde_with_value_affix::with_affix;

struct MyStruct {
    #[serde(with = "value_prefix_a")]
    code: u8,
    #[serde(with = "value_suffix_celsius")]
    temperature: f32,
}

with_affix!(value_suffix_meter Prefix "A");
with_affix!(value_suffix_celsius Suffix "C");

// Serializes
MyStruct {
    code: 12,
    temperature: -12.3,
};

// into
{
  "length": "A12",
  "temperature": "-12.3C"
}
Commit count: 12

cargo fmt