You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We've implemented some protocols that are designed to require all-zeroes in segments of the message. We ended up making this statically required by defining wrapper types around an enum. Example for u32:
#[derive(Clone,Copy,Default,IntoBytes,Immutable,FromZeros)]#[repr(u32)]enumAlignedZeroU32{#[default]Zero = 0,}#[repr(C, packed)]#[derive(Clone,Copy,Default,IntoBytes,FromZeros,Immutable)]pubstructZeroU32(AlignedZeroU32);implPartialEqforZeroU32{fneq(&self,other:&ZeroU32) -> bool{true}}impl fmt::DebugforZeroU32{fnfmt(&self,fmt:&mut fmt::Formatter<'_>) -> fmt::Result{// No need to debug the inner field.
fmt.debug_struct("ZeroU32").finish()}}// PartialEq against u32 with `== 0`, U32<T: zerocopy::byte_order::ByteOrder> with `== U32::ZERO`
There were enough hurdles to jump through to implement this correctly that it'd be convenient to have these as types within zerocopy. This doesn't use zerocopy::Unalign<AlignedZeroU32> because PartialEq and Debug require manual implementations
The text was updated successfully, but these errors were encountered:
We've implemented some protocols that are designed to require all-zeroes in segments of the message. We ended up making this statically required by defining wrapper types around an
enum
. Example foru32
:There were enough hurdles to jump through to implement this correctly that it'd be convenient to have these as types within
zerocopy
. This doesn't usezerocopy::Unalign<AlignedZeroU32>
becausePartialEq
andDebug
require manual implementationsThe text was updated successfully, but these errors were encountered: