Crate facet_format_postcard

Crate facet_format_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_format_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

Deserialization uses a multi-tier approach:

use facet_format_postcard::from_slice;

let bytes = &[0x03, 0x01, 0x00, 0x01];
let result: Vec<bool> = from_slice(bytes).unwrap();

The from_slice function automatically selects 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, making this crate a complete replacement for facet-postcard.

Structs§

PostcardError
Postcard parsing error with optional source context for diagnostics.
PostcardParser
Postcard parser for Tier-0 and Tier-2 deserialization.

Enums§

DeserializeError
Error produced by FormatDeserializer.
SerializeError
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 (non-JIT fallback).
to_vec
Serializes any Facet type to postcard bytes.
to_writer_fallible
Serializes any Facet type to a custom writer implementing the fallible Writer trait.