Skip to main content

Configuration

Struct Configuration 

Source
pub struct Configuration<const ZERO_COPY_ALIGN_CHECK: bool = true, const PREALLOCATION_SIZE_LIMIT: usize = DEFAULT_PREALLOCATION_SIZE_LIMIT, LengthEncoding = BincodeLen, ByteOrder = LittleEndian, IntEncoding = FixInt, TagEncoding = u32> { /* private fields */ }
Expand description

Compile-time configuration for runtime behavior.

Defaults:

  • Zero-copy alignment check is enabled.
  • Preallocation size limit is 4 MiB.
  • Length encoding is BincodeLen.
  • Byte order is LittleEndian.
  • Integer encoding is FixInt.
  • Tag encoding is u32.

Implementations§

Source§

impl Configuration

Source

pub const fn default() -> DefaultConfig

Create a new configuration with the default settings.

Defaults:

  • Zero-copy alignment check is enabled.
  • Preallocation size limit is 4 MiB.
  • Length encoding is BincodeLen.
  • Byte order is LittleEndian.
  • Integer encoding is FixInt.
Source§

impl<const ZERO_COPY_ALIGN_CHECK: bool, const PREALLOCATION_SIZE_LIMIT: usize, LengthEncoding, ByteOrder, IntEncoding, TagEncoding> Configuration<ZERO_COPY_ALIGN_CHECK, PREALLOCATION_SIZE_LIMIT, LengthEncoding, ByteOrder, IntEncoding, TagEncoding>

Source

pub const fn new() -> Self

Source

pub const fn with_length_encoding<L>( self, ) -> Configuration<ZERO_COPY_ALIGN_CHECK, PREALLOCATION_SIZE_LIMIT, L, ByteOrder, IntEncoding>
where Configuration<ZERO_COPY_ALIGN_CHECK, PREALLOCATION_SIZE_LIMIT, L>: Config,

Use the given SeqLen implementation for sequence length encoding.

Default is BincodeLen.

Note that this default can be overridden for individual cases by using containers.

Source

pub const fn with_big_endian( self, ) -> Configuration<ZERO_COPY_ALIGN_CHECK, PREALLOCATION_SIZE_LIMIT, LengthEncoding, BigEndian, IntEncoding>

Use big-endian byte order.

Note that changing the byte order will have a direct impact on zero-copy eligibility. Integers are only eligible for zero-copy when configured byte order matches the native byte order.

Default is LittleEndian.

Source

pub const fn with_little_endian( self, ) -> Configuration<ZERO_COPY_ALIGN_CHECK, PREALLOCATION_SIZE_LIMIT, LengthEncoding, LittleEndian, IntEncoding>

Use little-endian byte order.

Default is LittleEndian.

Source

pub const fn with_platform_endian( self, ) -> Configuration<ZERO_COPY_ALIGN_CHECK, PREALLOCATION_SIZE_LIMIT, LengthEncoding, LittleEndian, IntEncoding>

Available on little-endian only.

Use target platform byte order.

Will use the native byte order of the target platform.

Source

pub const fn with_fixint_encoding( self, ) -> Configuration<ZERO_COPY_ALIGN_CHECK, PREALLOCATION_SIZE_LIMIT, LengthEncoding, ByteOrder, FixInt>

Use FixInt for integer encoding.

Default is FixInt.

Source

pub const fn with_varint_encoding( self, ) -> Configuration<ZERO_COPY_ALIGN_CHECK, PREALLOCATION_SIZE_LIMIT, LengthEncoding, ByteOrder, VarInt>

Use VarInt for integer encoding.

Default is FixInt.

Performance note: variable length integer encoding will hurt serialization and deserialization performance significantly relative to fixed width integer encoding. Additionally, all zero-copy capabilities on integers will be lost. Variable length integer encoding may be beneficial if reducing the resulting size of serialized data is important, but if serialization / deserialization performance is important, fixed width integer encoding is highly recommended.

Source

pub const fn with_int_encoding<I>( self, ) -> Configuration<ZERO_COPY_ALIGN_CHECK, PREALLOCATION_SIZE_LIMIT, LengthEncoding, ByteOrder, I>
where Configuration<ZERO_COPY_ALIGN_CHECK, PREALLOCATION_SIZE_LIMIT, LengthEncoding, ByteOrder, I>: Config,

Use the given IntEncoding implementation for integer encoding.

Can be used for custom, unofficial integer encodings.

Default is FixInt.

Source

pub const fn enable_zero_copy_align_check( self, ) -> Configuration<true, PREALLOCATION_SIZE_LIMIT, LengthEncoding, ByteOrder, IntEncoding>

Enable the zero-copy alignment check.

If enabled, zero-copy deserialization will ensure that pointers are correctly aligned for the target type before creating references. You should keep this enabled unless you have a very specific use case for disabling it.

This is enabled by default.

Source

pub const unsafe fn disable_zero_copy_align_check( self, ) -> Configuration<false, PREALLOCATION_SIZE_LIMIT, LengthEncoding, ByteOrder, IntEncoding>

Disable the zero-copy alignment check.

When disabled, zero-copy deserialization (&'de T and &'de [T] for T: ZeroCopy) will not verify that pointers into the buffer are correctly aligned before forming references. Creating a misaligned reference is undefined behavior.

§Safety

You must guarantee every zero-copy reference is correctly aligned for its type.

This holds when:

  • The buffer is aligned to at least align_of::<T>() for each zero-copy type T, and each zero-copy read occurs at an offset that preserves that alignment.
  • Or you only deserialize types with alignment 1 (e.g., &[u8], &[u8; N], &str, etc).

Only disable this when you control the serialized layout and can enforce alignment; owned deserialization paths are unaffected.

Source

pub const fn with_preallocation_size_limit<const LIMIT: usize>( self, ) -> Configuration<ZERO_COPY_ALIGN_CHECK, LIMIT, LengthEncoding, ByteOrder, IntEncoding>

Set the preallocation size limit in bytes.

wincode will preallocate all sequences up to this limit, or error if the size of the allocation would exceed this limit. This is used to prevent malicious data from causing excessive memory usage or OOM.

The default limit is 4 MiB.

Source

pub const fn disable_preallocation_size_limit( self, ) -> Configuration<ZERO_COPY_ALIGN_CHECK, PREALLOCATION_SIZE_LIMIT_DISABLED, LengthEncoding, ByteOrder, IntEncoding>

Disable the preallocation size limit.

Warning: only do this if you absolutely trust your input.
Source

pub const fn with_tag_encoding<T>( self, ) -> Configuration<ZERO_COPY_ALIGN_CHECK, PREALLOCATION_SIZE_LIMIT, LengthEncoding, ByteOrder, IntEncoding, T>
where Configuration<ZERO_COPY_ALIGN_CHECK, PREALLOCATION_SIZE_LIMIT, LengthEncoding, ByteOrder, IntEncoding, T>: Config,

Use the given TagEncoding implementation for enum discriminant encoding.

Default is u32.

This can be overriden for individual cases with the #[wincode(tag_encoding = ...)] attribute.

Trait Implementations§

Source§

impl<const ZERO_COPY_ALIGN_CHECK: bool, const PREALLOCATION_SIZE_LIMIT: usize, LengthEncoding, ByteOrder, IntEncoding, TagEncoding> Clone for Configuration<ZERO_COPY_ALIGN_CHECK, PREALLOCATION_SIZE_LIMIT, LengthEncoding, ByteOrder, IntEncoding, TagEncoding>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<const ZERO_COPY_ALIGN_CHECK: bool, const PREALLOCATION_SIZE_LIMIT: usize, LengthEncoding, B, I, T> Config for Configuration<ZERO_COPY_ALIGN_CHECK, PREALLOCATION_SIZE_LIMIT, LengthEncoding, B, I, T>
where LengthEncoding: SeqLen<Self> + 'static, T: TagEncoding<Self>, B: ByteOrder, I: IntEncoding<B>,

Source§

type LengthEncoding = LengthEncoding

Source§

type TagEncoding = T

Source§

impl<const ZERO_COPY_ALIGN_CHECK: bool, const PREALLOCATION_SIZE_LIMIT: usize, LengthEncoding: 'static, B, I, TagEncoding: 'static> ConfigCore for Configuration<ZERO_COPY_ALIGN_CHECK, PREALLOCATION_SIZE_LIMIT, LengthEncoding, B, I, TagEncoding>
where B: ByteOrder, I: IntEncoding<B>,

Source§

impl<const ZERO_COPY_ALIGN_CHECK: bool, const PREALLOCATION_SIZE_LIMIT: usize, LengthEncoding, ByteOrder, IntEncoding, TagEncoding> Copy for Configuration<ZERO_COPY_ALIGN_CHECK, PREALLOCATION_SIZE_LIMIT, LengthEncoding, ByteOrder, IntEncoding, TagEncoding>

Auto Trait Implementations§

§

impl<const ZERO_COPY_ALIGN_CHECK: bool, const PREALLOCATION_SIZE_LIMIT: usize, LengthEncoding, ByteOrder, IntEncoding, TagEncoding> Freeze for Configuration<ZERO_COPY_ALIGN_CHECK, PREALLOCATION_SIZE_LIMIT, LengthEncoding, ByteOrder, IntEncoding, TagEncoding>

§

impl<const ZERO_COPY_ALIGN_CHECK: bool, const PREALLOCATION_SIZE_LIMIT: usize, LengthEncoding, ByteOrder, IntEncoding, TagEncoding> RefUnwindSafe for Configuration<ZERO_COPY_ALIGN_CHECK, PREALLOCATION_SIZE_LIMIT, LengthEncoding, ByteOrder, IntEncoding, TagEncoding>
where LengthEncoding: RefUnwindSafe, ByteOrder: RefUnwindSafe, IntEncoding: RefUnwindSafe, TagEncoding: RefUnwindSafe,

§

impl<const ZERO_COPY_ALIGN_CHECK: bool, const PREALLOCATION_SIZE_LIMIT: usize, LengthEncoding, ByteOrder, IntEncoding, TagEncoding> Send for Configuration<ZERO_COPY_ALIGN_CHECK, PREALLOCATION_SIZE_LIMIT, LengthEncoding, ByteOrder, IntEncoding, TagEncoding>
where LengthEncoding: Send, ByteOrder: Send, IntEncoding: Send, TagEncoding: Send,

§

impl<const ZERO_COPY_ALIGN_CHECK: bool, const PREALLOCATION_SIZE_LIMIT: usize, LengthEncoding, ByteOrder, IntEncoding, TagEncoding> Sync for Configuration<ZERO_COPY_ALIGN_CHECK, PREALLOCATION_SIZE_LIMIT, LengthEncoding, ByteOrder, IntEncoding, TagEncoding>
where LengthEncoding: Sync, ByteOrder: Sync, IntEncoding: Sync, TagEncoding: Sync,

§

impl<const ZERO_COPY_ALIGN_CHECK: bool, const PREALLOCATION_SIZE_LIMIT: usize, LengthEncoding, ByteOrder, IntEncoding, TagEncoding> Unpin for Configuration<ZERO_COPY_ALIGN_CHECK, PREALLOCATION_SIZE_LIMIT, LengthEncoding, ByteOrder, IntEncoding, TagEncoding>
where LengthEncoding: Unpin, ByteOrder: Unpin, IntEncoding: Unpin, TagEncoding: Unpin,

§

impl<const ZERO_COPY_ALIGN_CHECK: bool, const PREALLOCATION_SIZE_LIMIT: usize, LengthEncoding, ByteOrder, IntEncoding, TagEncoding> UnwindSafe for Configuration<ZERO_COPY_ALIGN_CHECK, PREALLOCATION_SIZE_LIMIT, LengthEncoding, ByteOrder, IntEncoding, TagEncoding>
where LengthEncoding: UnwindSafe, ByteOrder: UnwindSafe, IntEncoding: UnwindSafe, TagEncoding: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.