Expand description
§facet-postcard
§facet-postcard
Postcard serialization and deserialization for Facet types.
Postcard is a compact, efficient binary serialization format designed for embedded and no_std environments. This crate provides byte-for-byte compatible output with the standard postcard crate, while using Facet’s reflection capabilities instead of serde.
§Features
- Compact binary format optimized for size
- Byte-for-byte compatibility with the
postcardcrate no_stdsupport with theallocfeature- Zero-copy deserialization where possible
§Usage
use facet::Facet;
use facet_postcard::{to_vec, from_slice};
#[derive(Debug, Facet)]
struct Message {
id: u32,
payload: Vec<u8>,
}
// Serialize
let msg = Message { id: 42, payload: vec![1, 2, 3] };
let bytes = to_vec(&msg).unwrap();
// Deserialize
let decoded: Message = from_slice(&bytes).unwrap();For no_std environments without an allocator, use to_slice:
let mut buf = [0u8; 64];
let used = facet_postcard::to_slice(&msg, &mut buf).unwrap();§Feature Flags
std(default): Enables standard library supportalloc: Enables heap allocation without full std (forno_stdwith allocator)
§Sponsors
Thanks to all individual sponsors:
…along with corporate sponsors:
…without whom this work could not exist.
§Special thanks
The facet logo was drawn by Misiasart.
§License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Structs§
- Error
Path - A path through a type structure, recorded as a series of steps.
- Postcard
- A wrapper type for Postcard serialization and deserialization.
Enums§
- Deserialize
Error - Errors that can occur during postcard deserialization
- Error
Path Step - A single step in a path through a type structure.
- Serialize
Error - Errors that can occur during postcard serialization
Functions§
- from_
slice - Deserializes postcard-encoded data into a type that implements
Facet. - ptr_
to_ vec - Serializes any Facet Reflect Peek to postcard bytes.
- take_
from_ slice - Deserializes postcard-encoded data into a Facet value, returning the remaining bytes.
- to_
slice - Serializes any Facet type to a provided byte slice.
- to_vec
- Serializes any Facet type to postcard bytes.