pub struct UseIntLen<T, const PREALLOCATION_SIZE_LIMIT: usize = PREALLOCATION_SIZE_LIMIT_USE_CONFIG>(/* private fields */);Expand description
Use the configuration’s integer encoding for sequence length encoding.
For example, if the configuration’s integer encoding is FixInt, then UseIntLen<u64>
will use the fixed-width u64 encoding.
If the configuration’s integer encoding is VarInt, then UseIntLen<u64> will use
the variable-width u64 encoding.
This is bincode’s default behavior.
Allows overriding the preallocation size limit per individual use.
§Examples
Override the preallocation size limit to 8 bytes.
type Max8Bytes = UseIntLen<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, 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>,
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>,
Source§fn 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. Read more
Source§fn write(writer: impl Writer, len: usize) -> WriteResult<()>
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>
fn write_bytes_needed(len: usize) -> WriteResult<usize>
Calculate the number of bytes needed to write the given length. Read more
fn prealloc_check<T>(len: usize) -> Result<(), PreallocationError>
Source§fn 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. Read moreSource§fn 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. Read more
Auto Trait Implementations§
impl<T, const PREALLOCATION_SIZE_LIMIT: usize> Freeze for UseIntLen<T, PREALLOCATION_SIZE_LIMIT>where
PhantomData<T>: Freeze,
impl<T, const PREALLOCATION_SIZE_LIMIT: usize> RefUnwindSafe for UseIntLen<T, PREALLOCATION_SIZE_LIMIT>where
PhantomData<T>: RefUnwindSafe,
impl<T, const PREALLOCATION_SIZE_LIMIT: usize> Send for UseIntLen<T, PREALLOCATION_SIZE_LIMIT>where
PhantomData<T>: Send,
impl<T, const PREALLOCATION_SIZE_LIMIT: usize> Sync for UseIntLen<T, PREALLOCATION_SIZE_LIMIT>where
PhantomData<T>: Sync,
impl<T, const PREALLOCATION_SIZE_LIMIT: usize> Unpin for UseIntLen<T, PREALLOCATION_SIZE_LIMIT>where
PhantomData<T>: Unpin,
impl<T, const PREALLOCATION_SIZE_LIMIT: usize> UnsafeUnpin for UseIntLen<T, PREALLOCATION_SIZE_LIMIT>where
PhantomData<T>: UnsafeUnpin,
impl<T, const PREALLOCATION_SIZE_LIMIT: usize> UnwindSafe for UseIntLen<T, PREALLOCATION_SIZE_LIMIT>where
PhantomData<T>: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more