pub trait JsonSafeFields { }Expand description
Marker trait proving a type’s u64/i64 fields are protected for JS-safe JSON serialization.
§How it works
The #[json_safe_fields] attribute macro auto-implements this trait for annotated types.
The #[derive(JsonConvertible)] macro implements it for versioned enums and asserts
that all inner variant types also implement it.
§Compile errors
If you see the trait `JsonSafeFields` is not satisfied, it means a field type
in an annotated struct doesn’t implement this trait. Fix it by one of:
- Struct with u64 fields: add
#[cfg_attr(feature = "json-conversion", json_safe_fields)] - Simple enum/struct without u64: add
impl JsonSafeFields for MyType {}below BTreeMap<K, u64>field: add#[serde(with = "json_safe_generic_u64_value_map")]- New
type Foo = u64alias: add it toU64_ALIASESin the proc macro crate
§Why u64/i64 don’t implement this trait
A bare u64 is NOT JS-safe. Safety comes from #[serde(with = "json_safe_u64")]
applied at the field level. By excluding u64/i64 from this trait, the compiler
catches unprotected type aliases (type Foo = u64) and containers (Vec<u64>)
at compile time.