Expand description
Combinators for composing and building complex encodables.
This module provides utility types for building complex Encodable
types from simpler ones. These combinators allow common operations for
encoding values, such as conditional encoding, prefixes or custom byte
ordering.
These building blocks follow the Encodable
trait interface and can be
nested or chained together to define rich encoding behavior with minimal
boilerplate.
§Categories of Encodables
§Primitive and Built-in Encodables
These are the basic types that can be directly encoded.
Type | Description |
---|---|
(...) | Encodes a tuple by encoding each element in order |
i8 and u8 | Encodes a single byte |
char | Encodes a character as its UTF-8 byte representation |
str | Encodes a UTF-8 string slice |
CStr | Encodes a C string slice, including the null terminator (\0 ) |
[u8; N] | Encodes a byte array |
[u8] | Encodes a byte slice |
[bool; 8] | Encodes a set of flags as a single byte |
Arguments | Encodes formatted data from format_args with zero allocations |
§Composition and Flow Combinators
These types wrap or transform other encodables, allowing conditional encoding, iteration, or control over the format and structure of the output.
Type | Description |
---|---|
Option | Encodes the inner value if Some ; does nothing if None |
Result | Encodes the value on Ok ; returns the error on Err |
Cond | Encodes a value only if a condition is met |
LE | Encodes a number in little-endian order |
BE | Encodes a number in big-endian order |
LengthPrefix | Encodes a length prefixed value (TLV) |
Separated | Encodes a sequence of encodables separated by a given delimiter |
Iter | Encodes a sequence of encodables |
FromError | Transforms the error type of an encodable. |
§Alloc Encodables (requires the alloc
OR std
features)
These types are supported when the alloc
or std
feature is enabled.
Structs§
- BE
- Encodes a number in big-endian order.
- Cond
- Encodes a value only if a condition is met
- Flags
Deprecated - Encodes a set of bit flags packed into a single byte
- From
Error - Transforms the error type of an encodable.
- Iter
- Encodes a sequence of encodables.
- LE
- Encodes a number in little-endian order.
- Length
Prefix - Encodes a length prefixed value (TLV).
- Separated
- Encodes a sequence of encodables separated by a given delimiter.