pub struct Postbag;Available on crate feature
serde only.Expand description
Postbag codec with full forward and backward compatibility.
Postbag is a high-performance binary codec that provides efficient data encoding
with configurable levels of forward and backward compatibility. This codec uses the Full
configuration which provides maximum compatibility and schema evolution capabilities.
ยงKey Features
- Full fidelity of Rust type system: Supports all serde-compatible types including structs, enums, tuples, arrays, maps, and all primitive types
- Efficient binary format: Uses variable-length encoding (varint) for integers, compact representations for common types, and minimal overhead
- Full forward/backward compatibility: Fields and enum variants can be reordered, added, or removed safely
ยงForward and Backward Compatibility
The Full configuration provides comprehensive schema evolution capabilities:
- Field reordering: Struct fields can be reordered without breaking compatibility
- Field addition: New fields can be added to structs at any position
- Field removal: Existing fields can be removed without affecting deserialization
- Enum variant evolution: Enum variants can be added, removed, or reordered
- Schema evolution: Safe evolution of data structures over time
ยงNumerical Identifier Encoding
Fields named _0 through _59 are encoded with just a single byte instead of the full
string identifier. Use #[serde(rename = "...")] to specify numerical IDs:
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize)]
struct CompactData {
#[serde(rename = "_3")]
my_field: u32,
#[serde(rename = "_15")]
another_field: String,
// Regular field names work normally
normal_field: bool,
}This serializes and deserializes with field identifiers for maximum compatibility.
Trait Implementationsยง
Sourceยงimpl Codec for Postbag
impl Codec for Postbag
Sourceยงfn serialize<Writer, Item>(
writer: Writer,
item: &Item,
) -> Result<(), SerializationError>
fn serialize<Writer, Item>( writer: Writer, item: &Item, ) -> Result<(), SerializationError>
Serializes the specified item into the data format.
Sourceยงfn deserialize<Reader, Item>(
reader: Reader,
) -> Result<Item, DeserializationError>where
Reader: Read,
Item: DeserializeOwned,
fn deserialize<Reader, Item>(
reader: Reader,
) -> Result<Item, DeserializationError>where
Reader: Read,
Item: DeserializeOwned,
Deserializes the specified data into an item.
Sourceยงimpl<'de> Deserialize<'de> for Postbag
impl<'de> Deserialize<'de> for Postbag
Sourceยงfn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementationsยง
impl Freeze for Postbag
impl RefUnwindSafe for Postbag
impl Send for Postbag
impl Sync for Postbag
impl Unpin for Postbag
impl UnwindSafe for Postbag
Blanket Implementationsยง
Sourceยงimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Sourceยงfn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more