Skip to main content
A trait that allows for serializing and deserializing values of any type. The Serde trait defines two core operations:
  • serialize: Converts a value into a sequence of felt252s
  • deserialize: Reconstructs a value from a sequence of felt252s

Signature

Examples

Simple Types (u8, u16, u32, u64, u128)

Simple types are serialized into a single felt252:

Compound Types (u256)

Compound types may be serialized into multiple felt252 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 the Serde yourself:

Trait functions

serialize

Serializes a value into a sequence of felt252s.

Signature

Examples

deserialize

Deserializes a value from a sequence of felt252s. If the value cannot be deserialized, returns None.

Signature

Examples