Skip to main content

FixIntLen

Struct FixIntLen 

Source
pub struct FixIntLen<T, const PREALLOCATION_SIZE_LIMIT: usize = PREALLOCATION_SIZE_LIMIT_USE_CONFIG>(/* private fields */);
Expand description

Fixed-width integer length encoding.

Integers respect the configured byte order.

Allows overriding the preallocation size limit per individual use.

§Examples

Override the preallocation size limit to 8 bytes.

type Max8Bytes = FixIntLen<u32, 8>;

#[derive(SchemaWrite, SchemaRead)]
struct OverrideLen {
    #[wincode(with = "containers::Vec<u8, Max8Bytes>")]
    bytes: Vec<u8>,
}

let data_ok = OverrideLen { bytes: vec![0; 8] };
let serialized = wincode::serialize(&data_ok).unwrap();
assert!(wincode::deserialize::<OverrideLen>(&serialized).is_ok());

let data_err = OverrideLen { bytes: vec![0; 9] };
assert!(wincode::serialize(&data_err).is_err());
let serialized = wincode::serialize(&vec![0; 9]).unwrap();
assert!(wincode::deserialize::<OverrideLen>(&serialized).is_err());

Trait Implementations§

Source§

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

Source§

const PREALLOCATION_SIZE_LIMIT_OVERRIDE: PreallocationLimitOverride

SeqLen level override of configured preallocation size limit, in bytes. Read more
Source§

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

Read the length of a sequence, without doing any preallocation size checks. Read more
Source§

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

Write the length of a sequence to the writer.
Source§

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

Calculate the number of bytes needed to write the given length. Read more
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. Read more
Source§

fn write_bytes_needed_prealloc_check<T>(len: usize) -> WriteResult<usize>

Calculate the number of bytes needed to write the given length. Read more
Source§

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

Source§

const PREALLOCATION_SIZE_LIMIT_OVERRIDE: PreallocationLimitOverride

SeqLen level override of configured preallocation size limit, in bytes. Read more
Source§

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

Read the length of a sequence, without doing any preallocation size checks. Read more
Source§

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

Write the length of a sequence to the writer.
Source§

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

Calculate the number of bytes needed to write the given length. Read more
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. Read more
Source§

fn write_bytes_needed_prealloc_check<T>(len: usize) -> WriteResult<usize>

Calculate the number of bytes needed to write the given length. Read more
Source§

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

Source§

const PREALLOCATION_SIZE_LIMIT_OVERRIDE: PreallocationLimitOverride

SeqLen level override of configured preallocation size limit, in bytes. Read more
Source§

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

Read the length of a sequence, without doing any preallocation size checks. Read more
Source§

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

Write the length of a sequence to the writer.
Source§

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

Calculate the number of bytes needed to write the given length. Read more
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. Read more
Source§

fn write_bytes_needed_prealloc_check<T>(len: usize) -> WriteResult<usize>

Calculate the number of bytes needed to write the given length. Read more
Source§

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

Source§

const PREALLOCATION_SIZE_LIMIT_OVERRIDE: PreallocationLimitOverride

SeqLen level override of configured preallocation size limit, in bytes. Read more
Source§

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

Read the length of a sequence, without doing any preallocation size checks. Read more
Source§

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

Write the length of a sequence to the writer.
Source§

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

Calculate the number of bytes needed to write the given length. Read more
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. Read more
Source§

fn write_bytes_needed_prealloc_check<T>(len: usize) -> WriteResult<usize>

Calculate the number of bytes needed to write the given length. Read more
Source§

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

Source§

const PREALLOCATION_SIZE_LIMIT_OVERRIDE: PreallocationLimitOverride

SeqLen level override of configured preallocation size limit, in bytes. Read more
Source§

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

Read the length of a sequence, without doing any preallocation size checks. Read more
Source§

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

Write the length of a sequence to the writer.
Source§

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

Calculate the number of bytes needed to write the given length. Read more
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. Read more
Source§

fn write_bytes_needed_prealloc_check<T>(len: usize) -> WriteResult<usize>

Calculate the number of bytes needed to write the given length. Read more
Source§

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

Source§

const PREALLOCATION_SIZE_LIMIT_OVERRIDE: PreallocationLimitOverride

SeqLen level override of configured preallocation size limit, in bytes. Read more
Source§

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

Read the length of a sequence, without doing any preallocation size checks. Read more
Source§

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

Write the length of a sequence to the writer.
Source§

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

Calculate the number of bytes needed to write the given length. Read more
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. Read more
Source§

fn write_bytes_needed_prealloc_check<T>(len: usize) -> WriteResult<usize>

Calculate the number of bytes needed to write the given length. Read more
Source§

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

Source§

const PREALLOCATION_SIZE_LIMIT_OVERRIDE: PreallocationLimitOverride

SeqLen level override of configured preallocation size limit, in bytes. Read more
Source§

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

Read the length of a sequence, without doing any preallocation size checks. Read more
Source§

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

Write the length of a sequence to the writer.
Source§

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

Calculate the number of bytes needed to write the given length. Read more
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. Read more
Source§

fn write_bytes_needed_prealloc_check<T>(len: usize) -> WriteResult<usize>

Calculate the number of bytes needed to write the given length. Read more
Source§

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

Source§

const PREALLOCATION_SIZE_LIMIT_OVERRIDE: PreallocationLimitOverride

SeqLen level override of configured preallocation size limit, in bytes. Read more
Source§

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

Read the length of a sequence, without doing any preallocation size checks. Read more
Source§

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

Write the length of a sequence to the writer.
Source§

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

Calculate the number of bytes needed to write the given length. Read more
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. Read more
Source§

fn write_bytes_needed_prealloc_check<T>(len: usize) -> WriteResult<usize>

Calculate the number of bytes needed to write the given length. Read more
Source§

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

Source§

const PREALLOCATION_SIZE_LIMIT_OVERRIDE: PreallocationLimitOverride

SeqLen level override of configured preallocation size limit, in bytes. Read more
Source§

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

Read the length of a sequence, without doing any preallocation size checks. Read more
Source§

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

Write the length of a sequence to the writer.
Source§

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

Calculate the number of bytes needed to write the given length. Read more
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. Read more
Source§

fn write_bytes_needed_prealloc_check<T>(len: usize) -> WriteResult<usize>

Calculate the number of bytes needed to write the given length. Read more
Source§

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

Source§

const PREALLOCATION_SIZE_LIMIT_OVERRIDE: PreallocationLimitOverride

SeqLen level override of configured preallocation size limit, in bytes. Read more
Source§

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

Read the length of a sequence, without doing any preallocation size checks. Read more
Source§

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

Write the length of a sequence to the writer.
Source§

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

Calculate the number of bytes needed to write the given length. Read more
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. Read more
Source§

fn write_bytes_needed_prealloc_check<T>(len: usize) -> WriteResult<usize>

Calculate the number of bytes needed to write the given length. Read more

Auto Trait Implementations§

§

impl<T, const PREALLOCATION_SIZE_LIMIT: usize> Freeze for FixIntLen<T, PREALLOCATION_SIZE_LIMIT>
where PhantomData<T>: Freeze,

§

impl<T, const PREALLOCATION_SIZE_LIMIT: usize> RefUnwindSafe for FixIntLen<T, PREALLOCATION_SIZE_LIMIT>

§

impl<T, const PREALLOCATION_SIZE_LIMIT: usize> Send for FixIntLen<T, PREALLOCATION_SIZE_LIMIT>
where PhantomData<T>: Send,

§

impl<T, const PREALLOCATION_SIZE_LIMIT: usize> Sync for FixIntLen<T, PREALLOCATION_SIZE_LIMIT>
where PhantomData<T>: Sync,

§

impl<T, const PREALLOCATION_SIZE_LIMIT: usize> Unpin for FixIntLen<T, PREALLOCATION_SIZE_LIMIT>
where PhantomData<T>: Unpin,

§

impl<T, const PREALLOCATION_SIZE_LIMIT: usize> UnsafeUnpin for FixIntLen<T, PREALLOCATION_SIZE_LIMIT>

§

impl<T, const PREALLOCATION_SIZE_LIMIT: usize> UnwindSafe for FixIntLen<T, PREALLOCATION_SIZE_LIMIT>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.