pub unsafe trait SeqLen<C: ConfigCore> {
const PREALLOCATION_SIZE_LIMIT_OVERRIDE: PreallocationLimitOverride = PreallocationLimitOverride::UseConfig;
// Required methods
fn read<'de>(reader: impl Reader<'de>) -> ReadResult<usize>;
fn write(writer: impl Writer, len: usize) -> WriteResult<()>;
fn write_bytes_needed(len: usize) -> WriteResult<usize>;
// Provided methods
fn prealloc_check<T>(len: usize) -> Result<(), PreallocationError> { ... }
fn read_prealloc_check<'de, T>(
reader: impl Reader<'de>,
) -> ReadResult<usize> { ... }
fn write_bytes_needed_prealloc_check<T>(len: usize) -> WriteResult<usize> { ... }
}Expand description
Behavior to support heterogenous sequence length encoding.
It is possible for sequences to have different length encoding schemes. This trait abstracts over that possibility, allowing users to specify the length encoding scheme for a sequence.
§Safety
Implementors must adhere to the Safety section of the method write_bytes_needed.
Provided Associated Constants§
Sourceconst PREALLOCATION_SIZE_LIMIT_OVERRIDE: PreallocationLimitOverride = PreallocationLimitOverride::UseConfig
const PREALLOCATION_SIZE_LIMIT_OVERRIDE: PreallocationLimitOverride = PreallocationLimitOverride::UseConfig
Required Methods§
Sourcefn read<'de>(reader: impl Reader<'de>) -> ReadResult<usize>
fn read<'de>(reader: impl Reader<'de>) -> ReadResult<usize>
Read the length of a sequence, without doing any preallocation size checks.
Note this may still return typical read errors and there is no unsafety implied.
Sourcefn write(writer: impl Writer, len: usize) -> WriteResult<()>
fn write(writer: impl Writer, len: usize) -> WriteResult<()>
Write the length of a sequence to the writer.
Sourcefn write_bytes_needed(len: usize) -> WriteResult<usize>
fn write_bytes_needed(len: usize) -> WriteResult<usize>
Calculate the number of bytes needed to write the given length.
Useful for variable length encoding schemes.
§Safety
If Ok(…) is returned, it must contain the exact number of bytes
written by the write function for this particular object instance.
Provided Methods§
fn prealloc_check<T>(len: usize) -> Result<(), PreallocationError>
Sourcefn read_prealloc_check<'de, T>(reader: impl Reader<'de>) -> ReadResult<usize>
fn read_prealloc_check<'de, T>(reader: impl Reader<'de>) -> ReadResult<usize>
Read the length of a sequence from the reader, where
T is the type of the sequence elements. This can be used to
enforce size constraints for preallocations.
May return an error if some length condition is not met (e.g., size constraints, overflow, etc.).
Sourcefn write_bytes_needed_prealloc_check<T>(len: usize) -> WriteResult<usize>
fn write_bytes_needed_prealloc_check<T>(len: usize) -> WriteResult<usize>
Calculate the number of bytes needed to write the given length.
Return an error if the written size would be larger than the corresponding allocation limit while reading.
§Safety
If Ok(…) is returned, it must contain the exact number of bytes
written by the write function for this particular object instance.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".