| Crates.io | serde_with_value_affix |
| lib.rs | serde_with_value_affix |
| version | 0.1.0 |
| created_at | 2025-01-09 14:42:04.613498+00 |
| updated_at | 2025-01-09 14:42:04.613498+00 |
| description | Custom affix modules for serde |
| homepage | |
| repository | https://github.com/Detoo/serde-with-value-affix |
| max_upload_size | |
| id | 1509996 |
| size | 22,592 |
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.
[dependencies]
serde_with_value_affix = "0.1.0"
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"
}