Skip to main content

Crate facet_postcard

Crate facet_postcard 

Source
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 is a configurable Deserializer API plus convenience functions:

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§

DeserializeConfig
Deserialization safety/configuration options.
DeserializeError
Error produced by the format deserializer.
Deserializer
Builder-style postcard deserializer.
PostcardError
Postcard parsing error with optional source context for diagnostics.
PostcardParser
Postcard parser for Tier-0 and Tier-2 deserialization.
ScatterPlan
A scatter/gather postcard serialization plan.

Enums§

RawPostcard
Postcard-encoded opaque payload bytes.
Segment
A segment in a postcard scatter plan.
SerializeError
Errors that can occur during postcard serialization.

Constants§

DEFAULT_MAX_COLLECTION_ELEMENTS
Default maximum number of elements allowed in a decoded collection.

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_into
Deserialize postcard bytes into an existing Partial.
from_slice_into_borrowed
Deserialize postcard bytes into an existing Partial, allowing zero-copy borrowing.
from_slice_with_shape
Deserialize postcard bytes into a Value using shape information.
opaque_encoded_borrowed
Builds opaque adapter serialization inputs for borrowed postcard payload bytes.
opaque_encoded_owned
Builds opaque adapter serialization inputs for owned postcard payload bytes.
peek_to_scatter_plan
Serializes a Peek into a scatter plan.
peek_to_vec
Serializes a Peek reference to postcard bytes.
to_scatter_plan
Serializes a value into a scatter plan.
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 Writer trait.