Expand description
Common types for XDR (External Data Representation) encoding and decoding.
This crate provides length-constrained collection types for XDR serialization:
VecM- Generic vector with maximum length constraintBytesM- Byte vector with maximum length constraintStringM- String (as bytes) with maximum length constraint
§Features
alloc- Enables heap allocation support (required for most functionality)std- Enables standard library support (impliesalloc)serde- Enables serde serialization/deserialization (impliesalloc)schemars- Enables JSON Schema generation via schemars (impliesalloc)
§no_std Support
This crate is no_std by default. Enable the alloc feature for heap-allocated
collections, or std for full standard library support.
§Examples
ⓘ
use xdr_common::{VecM, BytesM, StringM};
// Create a vector with max length of 10
let v: VecM<u32, 10> = vec![1, 2, 3].try_into()?;
// Create a byte array with max length of 100
let b: BytesM<100> = b"hello".as_slice().try_into()?;
// Create a string with max length of 50
let s: StringM<50> = "world".try_into()?;Modules§
- serde_
hex serde - Serde adapter for fixed-size byte arrays encoded as hexadecimal strings.
Structs§
- BytesM
- A byte vector with a maximum length constraint.
- StringM
- A string type that stores arbitrary bytes with a maximum length constraint.
- VecM
- A vector with a maximum length constraint.
Enums§
- Error
- Errors that can occur when working with XDR types.
Constants§
- MAX_
PREALLOC_ BYTES alloc - The maximum number of bytes a decoder will preallocate for a variable-length collection before reading its elements.
Traits§
- Static
IfNo Alloc alloc - Helper trait bound on
VecMelements that requires'staticonly in no-allocbuilds.
Functions§
- box_
as_ ref alloc - Borrows the value behind a
Boxin aconstcontext.