Serde trait defines two core operations:
serialize: Converts a value into a sequence offelt252sdeserialize: Reconstructs a value from a sequence offelt252s
Signature
Examples
Simple Types (u8, u16, u32, u64, u128)
Simple types are serialized into a singlefelt252:
Compound Types (u256)
Compound types may be serialized into multiplefelt252 values:
Implementing Serde
Using the Derive Macro
In most cases, you can use the #[derive(Serde)] attribute to automatically generate the
implementation for your type:
Manual Implementation
Should you need to customize the serialization behavior for a type in a way that derive does not support, you can implement theSerde yourself:
Trait functions
serialize
Serializes a value into a sequence offelt252s.
Signature
Examples
deserialize
Deserializes a value from a sequence offelt252s.
If the value cannot be deserialized, returns None.