pub enum TypeMeta {
Static {
size: usize,
zero_copy: bool,
},
Dynamic,
}Expand description
Indicates what kind of assumptions can be made when encoding or decoding a type.
Readers and writers may use this to optimize their behavior.
Variants§
Static
The type has a statically known serialized size.
Specifying this variant can have significant performance benefits, as it can allow writers to prefetch larger chunks of memory such that subsequent read/write operations in those chunks can be performed at once without intermediate bounds checks.
Specifying this variant incorrectly will almost certainly result in a panic at runtime.
Take care not to specify this on variable length types, like Vec or String, as their
serialized size will vary based on their length.
Fields
Dynamic
The type has a dynamic size, and no optimizations can be made.
Implementations§
Source§impl TypeMeta
impl TypeMeta
Sourcepub const fn keep_zero_copy(self, keep_zero_copy: bool) -> Self
pub const fn keep_zero_copy(self, keep_zero_copy: bool) -> Self
Returns this TypeMeta instance with zero_copy masked by keep_zero_copy.
For TypeMeta::Static, this preserves size and computes:
zero_copy = zero_copy && keep_zero_copy.
For TypeMeta::Dynamic, this is a no-op.
This method never upgrades a type to zero-copy.
keep_zero_copy(true)leaves the flag unchanged.keep_zero_copy(false)clears the flag.
Sourcepub const fn join_types<const N: usize>(types: [Self; N]) -> Self
pub const fn join_types<const N: usize>(types: [Self; N]) -> Self
Combines multiple constituent TypeMeta values into one aggregate.
Intended for composite types whose constituents are serialized sequentially.
Semantics:
- If any input is
Dynamic, returnsDynamic. - Otherwise returns
Staticwith:size = sum of all constituent sizeszero_copy = logical AND of all constituent zero_copy flags
Notes:
- This function does not validate layout/padding; it only combines metadata.
- For
N = 0, the result isTypeMeta::Static { size: 0, zero_copy: true }. - The caller must ensure the summed size is meaningful for the target type.
use wincode::TypeMeta;
let types = [
TypeMeta::Static { size: 1, zero_copy: true },
TypeMeta::Static { size: 2, zero_copy: true },
TypeMeta::Dynamic,
TypeMeta::Static { size: 3, zero_copy: true },
];
assert_eq!(TypeMeta::join_types(types), TypeMeta::Dynamic);use wincode::TypeMeta;
let types = [
TypeMeta::Static { size: 1, zero_copy: true },
TypeMeta::Static { size: 2, zero_copy: true },
TypeMeta::Static { size: 3, zero_copy: true },
];
assert_eq!(TypeMeta::join_types(types), TypeMeta::Static { size: 6, zero_copy: true });use wincode::TypeMeta;
let types = [
TypeMeta::Static { size: 1, zero_copy: true },
TypeMeta::Static { size: 2, zero_copy: false },
TypeMeta::Static { size: 3, zero_copy: true },
];
assert_eq!(TypeMeta::join_types(types), TypeMeta::Static { size: 6, zero_copy: false });Trait Implementations§
impl Copy for TypeMeta
impl Eq for TypeMeta
impl StructuralPartialEq for TypeMeta
Auto Trait Implementations§
impl Freeze for TypeMeta
impl RefUnwindSafe for TypeMeta
impl Send for TypeMeta
impl Sync for TypeMeta
impl Unpin for TypeMeta
impl UnsafeUnpin for TypeMeta
impl UnwindSafe for TypeMeta
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.