kona-serde
Serde related helpers for kona.
Graceful Serialization
This crate extends the serialization and deserialization
functionality provided by alloy-serde to
deserialize raw number quantity values.
This issue arose in u128 toml deserialization where
deserialization of a raw number fails.
This rust playground demonstrates how toml fails to
deserialize a native u128 internal value.
With kona-serde, tagging the inner u128 field with #[serde(with = "kona_serde::quantity")],
allows the u128 or any other type within the following constraints to be deserialized by toml properly.
These are the supported native types:
boolu8u16u32u64u128
Below demonstrates the use of the #[serde(with = "kona_serde::quantity")] attribute.
use ;
/// My wrapper type.
// Correctly deserializes a raw value.
let raw_toml = r#"inner = 120"#;
let b: MyStruct = from_str.expect;
println!;
// Notice that a string value is also deserialized correctly.
let raw_toml = r#"inner = "120""#;
let b: MyStruct = from_str.expect;
println!;
Provenance
This code is heavily based on the alloy-serde crate.