Module combinators

Source
Expand description

Combinators for composing encodables.

This module contains a number of combinators that can be used to compose encodables. The objective is to provide a set of building blocks that can be combined to create more complex encodables that can be encoded into byte sequences.

§Available encodables

§Basic encodables

TypeDescription
(...)Encodes all encodables in sequence
i8, u8Encodes a single byte
charEncodes the character as a UTF-8 byte sequence
&strEncodes a string as a UTF-8 byte sequence
&CStrEncodes a string as a byte sequence with a null terminator (\0)
&[u8]Encodes a slice of bytes
Arguments(format_args!)Runs core::fmt machinery and encodes the result, without allocations

§Encodable combinators

TypeDescription
OptionEncodes T if Some, or does nothing on None
ResultEncodes T if Ok, or bubbles up E on Err
CondConditionally encodes an encodable if the given predicate is true
FlagsEncodes a set of bit flags as a byte
LEEncodes a number in little-endian order.
BEEncodes a number in big-endian order.
SeparatedEncodes a sequence of encodables separated by a delimiter.
LengthPrefixEncodes a value after its size.
IterEncodes an iterator of encodables as a sequence.

§alloc encodables (requires alloc feature)

TypeDescription
Vec<u8>Encodes a vector of bytes
StringEncodes a string as a UTF-8 byte sequence
CStringEncodes a string as a byte sequence with a null terminator (\0)
BoxEncodes a boxed value

Structs§

BE
Encodes a number in big-endian order.
Cond
Conditionally encodes an encodable.
Flags
A combinator that encodes a sequence of flags as a single byte.
FromError
A combinator that transforms the error type of an encodable.
Iter
A combinator that encodes an iterator of encodables as a sequence.
LE
Encodes a number in little-endian order.
LengthPrefix
Encodes a length prefixed value (TLV).
Separated
A combinator that encodes an iterator of encodables as a sequence with separators.