Skip to main content

serialize_value_with_shape

Function serialize_value_with_shape 

Source
pub fn serialize_value_with_shape<S>(
    serializer: &mut S,
    value: Peek<'_, '_>,
    target_shape: &'static Shape,
) -> Result<(), SerializeError<S::Error>>
Expand description

Serialize a dynamic value (like facet_value::Value) according to a target shape.

This is the inverse of FormatDeserializer::deserialize_with_shape. It allows serializing a Value as if it were a typed value matching the shape, without the dynamic value’s type discriminants.

This is useful for non-self-describing formats like postcard where you want to:

  1. Parse JSON into a Value
  2. Serialize it to postcard bytes matching a typed schema

§Arguments

  • serializer - The format serializer to use
  • value - A Peek into a dynamic value type (like facet_value::Value)
  • target_shape - The shape describing the expected wire format

§Errors

Returns an error if:

  • The value is not a dynamic value type
  • The value’s structure doesn’t match the target shape