pub const MAX_CONTAINER_PREALLOC: usize = 10_000;Expand description
Deserializes Smithy shapes from a serial format.
This trait provides a format-agnostic API for deserializing the Smithy data model. Implementations read from a serial format and create data objects based on schemas.
The deserializer uses a consumer pattern for aggregate types (structures, lists, maps) to avoid trait object limitations and enable efficient deserialization without intermediate allocations.
§Consumer Pattern
For aggregate types, the deserializer calls a consumer function for each element/member. The consumer receives mutable state and updates it with each deserialized value. This pattern:
- Avoids trait object issues with generic methods
- Enables zero-cost abstractions (closures can be inlined)
- Allows caller to control deserialization order and state management
- Matches the SEP’s recommendation for compiled typed languages
- Uses
&mut dyn ShapeDeserializerso composite deserializers (e.g., HTTP binding + body) can transparently delegate without the consumer knowing the concrete deserializer type. This enables runtime protocol swapping.
§Example
ⓘ
// Deserializing a structure
let mut builder = MyStructBuilder::default();
deserializer.read_struct(
&MY_STRUCT_SCHEMA,
&mut |member, deser| {
match member.member_index() {
Some(0) => builder.field1 = Some(deser.read_string(member)?),
Some(1) => builder.field2 = Some(deser.read_integer(member)?),
_ => {}
}
Ok(())
},
)?;
let my_struct = builder.build();Maximum pre-allocation size for containers, used to prevent denial-of-service from untrusted payloads claiming excessively large sizes.