Expand description
Postcard binary format for facet.
This crate provides serialization and deserialization for the postcard binary format.
§Serialization
Serialization supports all types that implement facet_core::Facet:
use facet::Facet;
use facet_postcard::to_vec;
#[derive(Facet)]
struct Point { x: i32, y: i32 }
let point = Point { x: 10, y: 20 };
let bytes = to_vec(&point).unwrap();§Deserialization
There are three deserialization functions:
from_slice: Deserializes into owned types (T: Facet<'static>)from_slice_borrowed: Deserializes with zero-copy borrowing from the input bufferfrom_slice_with_shape: Deserializes intoValueusing runtime shape information
use facet_postcard::from_slice;
// Postcard encoding: [length=3, true, false, true]
let bytes = &[0x03, 0x01, 0x00, 0x01];
let result: Vec<bool> = from_slice(bytes).unwrap();
assert_eq!(result, vec![true, false, true]);Both functions automatically select the best deserialization tier:
- Tier-2 (Format JIT): Fastest path for compatible types (primitives, structs, vecs, simple enums)
- Tier-0 (Reflection): Fallback for all other types (nested enums, complex types)
This ensures all Facet types can be deserialized.
Structs§
- Postcard
Error - Postcard parsing error with optional source context for diagnostics.
- Postcard
Parser - Postcard parser for Tier-0 and Tier-2 deserialization.
Enums§
- Deserialize
Error - Error produced by the format deserializer.
- Serialize
Error - Errors that can occur during postcard serialization.
Traits§
- Writer
- A trait for writing bytes during serialization with error handling.
Functions§
- from_
slice - Deserialize a value from postcard bytes into an owned type.
- from_
slice_ borrowed - Deserialize a value from postcard bytes, allowing zero-copy borrowing.
- from_
slice_ with_ shape - Deserialize postcard bytes into a
Valueusing shape information. - peek_
to_ vec - Serializes a
Peekreference to postcard bytes. - to_vec
- Serializes any Facet type to postcard bytes.
- to_
vec_ with_ shape - Serializes a dynamic value (like
facet_value::Value) to postcard bytes using a target shape to guide the serialization. - to_
writer_ fallible - Serializes any Facet type to a custom writer implementing the fallible
Writertrait.