1 unstable release
0.1.0 | Jan 9, 2025 |
---|
#1142 in Encoding
126 downloads per month
10KB
115 lines
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"
}
Dependencies
~0.7–1.6MB
~33K SLoC