#[repr(C, packed(1))]pub struct Unaligned<Data>(/* private fields */)
where
Data: TrivialType;
Expand description
Wrapper type for Data
that is the same size, but doesn’t need to be aligned/has alignment of
one byte.
This is similar to #[repr(packed)]
, but makes sure to only expose safe API when dealing with
the contents. For example, if Data
is unaligned and has fields, it is not sounds having
references to its fields. This data structure prevents such invalid invariants.
Implementations§
Trait Implementations§
Source§impl<Data> Decode for Unaligned<Data>where
Data: TrivialType + Decode,
impl<Data> Decode for Unaligned<Data>where
Data: TrivialType + Decode,
Source§fn decode<__CodecInputEdqy: Input>(
__codec_input_edqy: &mut __CodecInputEdqy,
) -> Result<Self, Error>
fn decode<__CodecInputEdqy: Input>( __codec_input_edqy: &mut __CodecInputEdqy, ) -> Result<Self, Error>
Attempt to deserialise the value from input.
§fn decode_into<I>(
input: &mut I,
dst: &mut MaybeUninit<Self>,
) -> Result<DecodeFinished, Error>where
I: Input,
fn decode_into<I>(
input: &mut I,
dst: &mut MaybeUninit<Self>,
) -> Result<DecodeFinished, Error>where
I: Input,
Attempt to deserialize the value from input into a pre-allocated piece of memory. Read more
§fn skip<I>(input: &mut I) -> Result<(), Error>where
I: Input,
fn skip<I>(input: &mut I) -> Result<(), Error>where
I: Input,
Attempt to skip the encoded value from input. Read more
§fn encoded_fixed_size() -> Option<usize>
fn encoded_fixed_size() -> Option<usize>
Returns the fixed encoded size of the type. Read more
Source§impl<'de, Data> Deserialize<'de> for Unaligned<Data>where
Data: TrivialType + Deserialize<'de>,
impl<'de, Data> Deserialize<'de> for Unaligned<Data>where
Data: TrivialType + Deserialize<'de>,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<Data> Encode for Unaligned<Data>where
Data: TrivialType + Encode,
impl<Data> Encode for Unaligned<Data>where
Data: TrivialType + Encode,
Source§fn size_hint(&self) -> usize
fn size_hint(&self) -> usize
If possible give a hint of expected size of the encoding. Read more
Source§fn encode_to<T: Output + ?Sized>(&self, dest: &mut T)
fn encode_to<T: Output + ?Sized>(&self, dest: &mut T)
Convert self to a slice and append it to the destination.
Source§fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R
fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R
Convert self to a slice and then invoke the given closure with it.
§fn encoded_size(&self) -> usize
fn encoded_size(&self) -> usize
Calculates the encoded size. Read more
Source§impl<Data> From<Data> for Unaligned<Data>where
Data: TrivialType,
impl<Data> From<Data> for Unaligned<Data>where
Data: TrivialType,
Source§impl<Data> MaxEncodedLen for Unaligned<Data>where
Data: TrivialType + MaxEncodedLen,
impl<Data> MaxEncodedLen for Unaligned<Data>where
Data: TrivialType + MaxEncodedLen,
Source§fn max_encoded_len() -> usize
fn max_encoded_len() -> usize
Upper bound, in bytes, of the maximum encoded size of this item.
Source§impl<Data> Ord for Unaligned<Data>
impl<Data> Ord for Unaligned<Data>
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl<Data> PartialOrd for Unaligned<Data>
impl<Data> PartialOrd for Unaligned<Data>
Source§impl<Data> TrivialType for Unaligned<Data>where
Data: TrivialType,
impl<Data> TrivialType for Unaligned<Data>where
Data: TrivialType,
Source§const METADATA: &[u8]
const METADATA: &[u8]
Data structure metadata in binary form, describing shape and types of the contents, see
IoTypeMetadataKind
for encoding details.const SIZE: u32 = _
Source§unsafe fn from_bytes(bytes: &[u8]) -> Option<&Self>
unsafe fn from_bytes(bytes: &[u8]) -> Option<&Self>
Create a reference to a type, which is represented by provided memory. Read more
Source§impl<Data> TypeInfo for Unaligned<Data>where
Data: TrivialType + TypeInfo + 'static,
impl<Data> TypeInfo for Unaligned<Data>where
Data: TrivialType + TypeInfo + 'static,
impl<Data> Copy for Unaligned<Data>where
Data: TrivialType + Copy,
impl<Data> EncodeLike for Unaligned<Data>where
Data: TrivialType + Encode,
impl<Data> Eq for Unaligned<Data>
impl<Data> StructuralPartialEq for Unaligned<Data>where
Data: TrivialType,
Auto Trait Implementations§
impl<Data> Freeze for Unaligned<Data>where
Data: Freeze,
impl<Data> RefUnwindSafe for Unaligned<Data>where
Data: RefUnwindSafe,
impl<Data> Send for Unaligned<Data>where
Data: Send,
impl<Data> Sync for Unaligned<Data>where
Data: Sync,
impl<Data> Unpin for Unaligned<Data>where
Data: Unpin,
impl<Data> UnwindSafe for Unaligned<Data>where
Data: 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> DecodeAll for Twhere
T: Decode,
impl<T> DecodeAll for Twhere
T: Decode,
§fn decode_all(input: &mut &[u8]) -> Result<T, Error>
fn decode_all(input: &mut &[u8]) -> Result<T, Error>
Decode
Self
and consume all of the given input data. Read more§impl<T> DecodeLimit for Twhere
T: Decode,
impl<T> DecodeLimit for Twhere
T: Decode,
Source§impl<T> IoType for Twhere
T: TrivialType,
impl<T> IoType for Twhere
T: TrivialType,
Source§const METADATA: &'static [u8] = const METADATA: &'_ [u8] = T::METADATA;
const METADATA: &'static [u8] = const METADATA: &'_ [u8] = T::METADATA;
Data structure metadata in binary form, describing shape and types of the contents, see
IoTypeMetadataKind
for encoding detailsSource§type PointerType = T
type PointerType = T
Pointer with trivial type that this
IoType
representsSource§unsafe fn size_ptr(&self) -> impl Deref<Target = NonNull<u32>>
unsafe fn size_ptr(&self) -> impl Deref<Target = NonNull<u32>>
Pointer to the number of bytes that are currently used to store data. Read more
Source§unsafe fn size_mut_ptr(&mut self) -> impl DerefMut
unsafe fn size_mut_ptr(&mut self) -> impl DerefMut
An exclusive pointer to the number of bytes that are currently used to store data. Read more
Source§unsafe fn capacity_ptr(&self) -> impl Deref<Target = NonNull<u32>>
unsafe fn capacity_ptr(&self) -> impl Deref<Target = NonNull<u32>>
Number of bytes are allocated right now Read more
Source§unsafe fn from_ptr<'a>(
ptr: &'a NonNull<<T as IoType>::PointerType>,
size: &'a u32,
capacity: u32,
) -> impl Deref<Target = T> + 'a
unsafe fn from_ptr<'a>( ptr: &'a NonNull<<T as IoType>::PointerType>, size: &'a u32, capacity: u32, ) -> impl Deref<Target = T> + 'a
Create a reference to a type, which is represented by provided memory. Read more
Source§unsafe fn from_mut_ptr<'a>(
ptr: &'a mut NonNull<<T as IoType>::PointerType>,
_size: &'a mut *mut u32,
capacity: u32,
) -> impl DerefMut + 'a
unsafe fn from_mut_ptr<'a>( ptr: &'a mut NonNull<<T as IoType>::PointerType>, _size: &'a mut *mut u32, capacity: u32, ) -> impl DerefMut + 'a
Create a mutable reference to a type, which is represented by provided memory. Read more
Source§unsafe fn as_ptr(
&self,
) -> impl Deref<Target = NonNull<<T as IoType>::PointerType>>
unsafe fn as_ptr( &self, ) -> impl Deref<Target = NonNull<<T as IoType>::PointerType>>
Get a raw pointer to the underlying data with no checks. Read more
Source§unsafe fn as_mut_ptr(&mut self) -> impl DerefMut
unsafe fn as_mut_ptr(&mut self) -> impl DerefMut
Get an exclusive raw pointer to the underlying data with no checks. Read more