Skip to main content

SeqLen

Trait SeqLen 

Source
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§

Source

const PREALLOCATION_SIZE_LIMIT_OVERRIDE: PreallocationLimitOverride = PreallocationLimitOverride::UseConfig

SeqLen level override of configured preallocation size limit, in bytes.

Allows specializing specific uses of a given SeqLen implementation to override any configured preallocation size limit.

Required Methods§

Source

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.

Source

fn write(writer: impl Writer, len: usize) -> WriteResult<()>

Write the length of a sequence to the writer.

Source

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§

Source

fn prealloc_check<T>(len: usize) -> Result<(), PreallocationError>

Source

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.).

Source

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".

Implementations on Foreign Types§

Source§

impl<C: ConfigCore> SeqLen<C> for i8

Source§

fn read<'de>(reader: impl Reader<'de>) -> ReadResult<usize>

Source§

fn write(writer: impl Writer, len: usize) -> WriteResult<()>

Source§

fn write_bytes_needed(len: usize) -> WriteResult<usize>

Source§

impl<C: ConfigCore> SeqLen<C> for i16

Source§

fn read<'de>(reader: impl Reader<'de>) -> ReadResult<usize>

Source§

fn write(writer: impl Writer, len: usize) -> WriteResult<()>

Source§

fn write_bytes_needed(len: usize) -> WriteResult<usize>

Source§

impl<C: ConfigCore> SeqLen<C> for i32

Source§

fn read<'de>(reader: impl Reader<'de>) -> ReadResult<usize>

Source§

fn write(writer: impl Writer, len: usize) -> WriteResult<()>

Source§

fn write_bytes_needed(len: usize) -> WriteResult<usize>

Source§

impl<C: ConfigCore> SeqLen<C> for i64

Source§

fn read<'de>(reader: impl Reader<'de>) -> ReadResult<usize>

Source§

fn write(writer: impl Writer, len: usize) -> WriteResult<()>

Source§

fn write_bytes_needed(len: usize) -> WriteResult<usize>

Source§

impl<C: ConfigCore> SeqLen<C> for i128

Source§

fn read<'de>(reader: impl Reader<'de>) -> ReadResult<usize>

Source§

fn write(writer: impl Writer, len: usize) -> WriteResult<()>

Source§

fn write_bytes_needed(len: usize) -> WriteResult<usize>

Source§

impl<C: ConfigCore> SeqLen<C> for u8

Source§

fn read<'de>(reader: impl Reader<'de>) -> ReadResult<usize>

Source§

fn write(writer: impl Writer, len: usize) -> WriteResult<()>

Source§

fn write_bytes_needed(len: usize) -> WriteResult<usize>

Source§

impl<C: ConfigCore> SeqLen<C> for u16

Source§

fn read<'de>(reader: impl Reader<'de>) -> ReadResult<usize>

Source§

fn write(writer: impl Writer, len: usize) -> WriteResult<()>

Source§

fn write_bytes_needed(len: usize) -> WriteResult<usize>

Source§

impl<C: ConfigCore> SeqLen<C> for u32

Source§

fn read<'de>(reader: impl Reader<'de>) -> ReadResult<usize>

Source§

fn write(writer: impl Writer, len: usize) -> WriteResult<()>

Source§

fn write_bytes_needed(len: usize) -> WriteResult<usize>

Source§

impl<C: ConfigCore> SeqLen<C> for u64

Source§

fn read<'de>(reader: impl Reader<'de>) -> ReadResult<usize>

Source§

fn write(writer: impl Writer, len: usize) -> WriteResult<()>

Source§

fn write_bytes_needed(len: usize) -> WriteResult<usize>

Source§

impl<C: ConfigCore> SeqLen<C> for u128

Source§

fn read<'de>(reader: impl Reader<'de>) -> ReadResult<usize>

Source§

fn write(writer: impl Writer, len: usize) -> WriteResult<()>

Source§

fn write_bytes_needed(len: usize) -> WriteResult<usize>

Implementors§

Source§

impl<const PREALLOCATION_SIZE_LIMIT: usize, C: ConfigCore> SeqLen<C> for FixIntLen<i8, PREALLOCATION_SIZE_LIMIT>

Source§

impl<const PREALLOCATION_SIZE_LIMIT: usize, C: ConfigCore> SeqLen<C> for FixIntLen<i16, PREALLOCATION_SIZE_LIMIT>

Source§

impl<const PREALLOCATION_SIZE_LIMIT: usize, C: ConfigCore> SeqLen<C> for FixIntLen<i32, PREALLOCATION_SIZE_LIMIT>

Source§

impl<const PREALLOCATION_SIZE_LIMIT: usize, C: ConfigCore> SeqLen<C> for FixIntLen<i64, PREALLOCATION_SIZE_LIMIT>

Source§

impl<const PREALLOCATION_SIZE_LIMIT: usize, C: ConfigCore> SeqLen<C> for FixIntLen<i128, PREALLOCATION_SIZE_LIMIT>

Source§

impl<const PREALLOCATION_SIZE_LIMIT: usize, C: ConfigCore> SeqLen<C> for FixIntLen<u8, PREALLOCATION_SIZE_LIMIT>

Source§

impl<const PREALLOCATION_SIZE_LIMIT: usize, C: ConfigCore> SeqLen<C> for FixIntLen<u16, PREALLOCATION_SIZE_LIMIT>

Source§

impl<const PREALLOCATION_SIZE_LIMIT: usize, C: ConfigCore> SeqLen<C> for FixIntLen<u32, PREALLOCATION_SIZE_LIMIT>

Source§

impl<const PREALLOCATION_SIZE_LIMIT: usize, C: ConfigCore> SeqLen<C> for FixIntLen<u64, PREALLOCATION_SIZE_LIMIT>

Source§

impl<const PREALLOCATION_SIZE_LIMIT: usize, C: ConfigCore> SeqLen<C> for FixIntLen<u128, PREALLOCATION_SIZE_LIMIT>

Source§

impl<const PREALLOCATION_SIZE_LIMIT: usize, T, C: ConfigCore> SeqLen<C> for UseIntLen<T, PREALLOCATION_SIZE_LIMIT>
where T: SchemaWrite<C> + for<'de> SchemaRead<'de, C>, T::Src: TryFrom<usize>, usize: for<'de> TryFrom<<T as SchemaRead<'de, C>>::Dst>,