pub unsafe trait Pod: Sized {
Show 52 methods
// Provided methods
unsafe fn uninitialized() -> Self { ... }
fn zeroed() -> Self { ... }
fn copy(&self) -> Self { ... }
fn map<T: Pod>(&self) -> Option<&T> { ... }
fn map_mut<T: Pod>(&mut self) -> Option<&mut T> { ... }
fn map_copy<T: Pod>(&self) -> Option<T> { ... }
fn try_map<T: Pod>(&self) -> Option<&T> { ... }
fn try_map_mut<T: Pod>(&mut self) -> Option<&mut T> { ... }
fn try_map_copy<T: Pod>(&self) -> Option<T> { ... }
fn map_box<T: Pod>(self: Box<Self>) -> Result<Box<T>, Box<Self>> { ... }
fn split<T: Pod>(&self) -> Option<&[T]> { ... }
fn split_mut<T: Pod>(&mut self) -> Option<&mut [T]> { ... }
fn try_split<T: Pod>(&self) -> &[T] { ... }
fn try_split_mut<T: Pod>(&mut self) -> &mut [T] { ... }
fn split_box<T: Pod>(self: Box<Self>) -> Result<Box<[T]>, Box<Self>> { ... }
fn split_vec<T: Pod>(self: Box<Self>) -> Result<Vec<T>, Box<Self>> { ... }
fn map_slice<T: Pod>(s: &[Self]) -> Option<&[T]> { ... }
fn map_slice_mut<T: Pod>(s: &mut [Self]) -> Option<&mut [T]> { ... }
fn try_map_slice<T: Pod>(s: &[Self]) -> &[T] { ... }
fn try_map_slice_mut<T: Pod>(s: &mut [Self]) -> &mut [T] { ... }
fn map_slice_box<T: Pod>(s: Box<[Self]>) -> Result<Box<[T]>, Box<[Self]>> { ... }
fn map_slice_vec<T: Pod>(s: Vec<Self>) -> Result<Vec<T>, Vec<Self>> { ... }
fn merge<T: Pod>(s: &[Self]) -> Option<&T> { ... }
fn merge_mut<T: Pod>(s: &mut [Self]) -> Option<&mut T> { ... }
fn merge_copy<T: Pod>(s: &[Self]) -> Option<T> { ... }
fn try_merge<T: Pod>(s: &[Self]) -> Option<&T> { ... }
fn try_merge_mut<T: Pod>(s: &mut [Self]) -> Option<&mut T> { ... }
fn try_merge_copy<T: Pod>(s: &[Self]) -> Option<T> { ... }
fn merge_box<T: Pod>(s: Box<[Self]>) -> Result<Box<T>, Box<[Self]>> { ... }
fn merge_vec<T: Pod>(s: Vec<Self>) -> Result<Box<T>, Vec<Self>> { ... }
unsafe fn from_ptr<T>(source: *const T) -> Self { ... }
fn from_ref<T: Pod>(p: &T) -> Option<Self> { ... }
fn from_slice<T: Pod>(p: &[T]) -> Option<Self> { ... }
fn from_boxed_slice<T: Pod>(p: Box<[T]>) -> Result<Box<Self>, Box<[T]>> { ... }
fn from_vec<T: Pod>(p: Vec<T>) -> Result<Box<Self>, Vec<T>> { ... }
fn slice_from_boxed_slice<T: Pod>(
p: Box<[T]>,
) -> Result<Box<[Self]>, Box<[T]>> { ... }
fn ref_from<T: Pod>(p: &T) -> Option<&Self> { ... }
fn ref_from_mut<T: Pod>(p: &mut T) -> Option<&mut Self> { ... }
fn ref_from_slice<T: Pod>(p: &[T]) -> Option<&Self> { ... }
fn ref_from_slice_mut<T: Pod>(p: &mut [T]) -> Option<&mut Self> { ... }
fn as_bytes(&self) -> &[u8] ⓘ { ... }
fn as_bytes_mut(&mut self) -> &mut [u8] ⓘ { ... }
fn from_bytes(p: &[u8]) -> Option<Self> { ... }
fn ref_from_bytes(p: &[u8]) -> Option<&Self> { ... }
fn ref_from_bytes_mut(p: &mut [u8]) -> Option<&mut Self> { ... }
fn from_byte_slice(p: Box<[u8]>) -> Result<Box<Self>, Box<[u8]>> { ... }
fn from_byte_vec(p: Vec<u8>) -> Result<Box<Self>, Vec<u8>> { ... }
fn into_byte_slice(self: Box<Self>) -> Box<[u8]> { ... }
fn into_byte_vec(self: Box<Self>) -> Vec<u8> ⓘ { ... }
fn as_aligned_mut<T: Pod + Aligned<Unaligned = Self>>(
&mut self,
) -> Option<&mut T>
where Self: Copy + Unaligned { ... }
fn from_unaligned_mut<T: Copy + Unaligned>(s: &mut T) -> Option<&mut Self>
where Self: Aligned<Unaligned = T> { ... }
fn from_unaligned<T: Copy + Unaligned>(s: T) -> Self
where Self: Aligned<Unaligned = T> { ... }
}
Expand description
A marker trait indicating that a type is Plain Old Data.
It is unsafe to impl
this manually, use #[derive(Pod)]
instead.
Provided Methods§
Sourceunsafe fn uninitialized() -> Self
unsafe fn uninitialized() -> Self
Generates a new uninitialized instance of a POD type.
Sourcefn map<T: Pod>(&self) -> Option<&T>
fn map<T: Pod>(&self) -> Option<&T>
Converts a POD reference from one to another type of the same size.
Returns None
if the two types are misaligned or not the same size.
Sourcefn map_mut<T: Pod>(&mut self) -> Option<&mut T>
fn map_mut<T: Pod>(&mut self) -> Option<&mut T>
Converts a mutable POD reference from one to another type of the same size.
Returns None
if the two types are misaligned or not the same size.
Sourcefn map_copy<T: Pod>(&self) -> Option<T>
fn map_copy<T: Pod>(&self) -> Option<T>
Converts a POD type from one to another of the same size.
Returns None
if the two types are not the same size.
Sourcefn try_map<T: Pod>(&self) -> Option<&T>
fn try_map<T: Pod>(&self) -> Option<&T>
Converts a POD reference from one to another type of the same or lesser size.
Returns None
if the two types are misaligned or T
is larger.
Sourcefn try_map_mut<T: Pod>(&mut self) -> Option<&mut T>
fn try_map_mut<T: Pod>(&mut self) -> Option<&mut T>
Converts a mutable POD reference from one to another type of the same or lesser size.
Returns None
if the two types are misaligned or T
is larger.
Sourcefn try_map_copy<T: Pod>(&self) -> Option<T>
fn try_map_copy<T: Pod>(&self) -> Option<T>
Converts a POD type from one to another of the same or lesser size.
Returns None
if T
is larger.
Sourcefn map_box<T: Pod>(self: Box<Self>) -> Result<Box<T>, Box<Self>>
fn map_box<T: Pod>(self: Box<Self>) -> Result<Box<T>, Box<Self>>
Converts a boxed POD type from one to another of the same size.
Fails if the two types are misaligned or not the same size.
Sourcefn split<T: Pod>(&self) -> Option<&[T]>
fn split<T: Pod>(&self) -> Option<&[T]>
Converts a POD reference into a slice of another type.
Returns None
if the types are misaligned or do not fit perfectly.
Sourcefn split_mut<T: Pod>(&mut self) -> Option<&mut [T]>
fn split_mut<T: Pod>(&mut self) -> Option<&mut [T]>
Converts a mutable POD reference into a slice of another type.
Returns None
if the types are misaligned or do not fit perfectly.
Sourcefn try_split<T: Pod>(&self) -> &[T]
fn try_split<T: Pod>(&self) -> &[T]
Converts a POD reference into a slice of another type.
Returns an empty slice if the types are misaligned.
Sourcefn try_split_mut<T: Pod>(&mut self) -> &mut [T]
fn try_split_mut<T: Pod>(&mut self) -> &mut [T]
Converts a mutable POD reference into a slice of another type.
Returns an empty slice if the types are misaligned.
Sourcefn split_box<T: Pod>(self: Box<Self>) -> Result<Box<[T]>, Box<Self>>
fn split_box<T: Pod>(self: Box<Self>) -> Result<Box<[T]>, Box<Self>>
Converts a boxed POD object into a boxed slice of another type.
Fails if the types are misaligned or do not fit perfectly.
Sourcefn split_vec<T: Pod>(self: Box<Self>) -> Result<Vec<T>, Box<Self>>
fn split_vec<T: Pod>(self: Box<Self>) -> Result<Vec<T>, Box<Self>>
Converts a boxed POD object into a vector of another type.
Fails if the types are misaligned or do not fit perfectly.
Sourcefn map_slice<T: Pod>(s: &[Self]) -> Option<&[T]>
fn map_slice<T: Pod>(s: &[Self]) -> Option<&[T]>
Maps a POD slice from one type to another.
Returns None
if the slice is misaligned or the output type does not perfectly fit.
Sourcefn map_slice_mut<T: Pod>(s: &mut [Self]) -> Option<&mut [T]>
fn map_slice_mut<T: Pod>(s: &mut [Self]) -> Option<&mut [T]>
Maps a mutable POD slice from one type to another.
Returns None
if the slice is misaligned or the output type does not perfectly fit.
Sourcefn try_map_slice<T: Pod>(s: &[Self]) -> &[T]
fn try_map_slice<T: Pod>(s: &[Self]) -> &[T]
Maps a POD slice from one type to another.
Returns None
if the slice is misaligned.
Sourcefn try_map_slice_mut<T: Pod>(s: &mut [Self]) -> &mut [T]
fn try_map_slice_mut<T: Pod>(s: &mut [Self]) -> &mut [T]
Maps a mutable POD slice from one type to another.
Returns None
if the slice is misaligned.
Sourcefn map_slice_box<T: Pod>(s: Box<[Self]>) -> Result<Box<[T]>, Box<[Self]>>
fn map_slice_box<T: Pod>(s: Box<[Self]>) -> Result<Box<[T]>, Box<[Self]>>
Maps a boxed POD slice from one type to another.
Fails if the slice is misaligned or does not perfectly fit.
Sourcefn map_slice_vec<T: Pod>(s: Vec<Self>) -> Result<Vec<T>, Vec<Self>>
fn map_slice_vec<T: Pod>(s: Vec<Self>) -> Result<Vec<T>, Vec<Self>>
Maps a POD vector from one type to another.
Fails if the slice is misaligned or does not perfectly fit.
Sourcefn merge<T: Pod>(s: &[Self]) -> Option<&T>
fn merge<T: Pod>(s: &[Self]) -> Option<&T>
Converts a POD slice into another type.
Returns None
if the types are misaligned or not the same size.
Sourcefn merge_mut<T: Pod>(s: &mut [Self]) -> Option<&mut T>
fn merge_mut<T: Pod>(s: &mut [Self]) -> Option<&mut T>
Converts a mutable POD slice into another type.
Returns None
if the types are misaligned or not the same size.
Sourcefn merge_copy<T: Pod>(s: &[Self]) -> Option<T>
fn merge_copy<T: Pod>(s: &[Self]) -> Option<T>
Converts a POD slice into another type.
Returns None
if the types are not the same size.
Sourcefn try_merge<T: Pod>(s: &[Self]) -> Option<&T>
fn try_merge<T: Pod>(s: &[Self]) -> Option<&T>
Converts a POD slice into another type.
Returns None
if the types are misaligned or T
is larger.
Sourcefn try_merge_mut<T: Pod>(s: &mut [Self]) -> Option<&mut T>
fn try_merge_mut<T: Pod>(s: &mut [Self]) -> Option<&mut T>
Converts a mutable POD slice into another type.
Returns None
if the types are misaligned or T
is larger.
Sourcefn try_merge_copy<T: Pod>(s: &[Self]) -> Option<T>
fn try_merge_copy<T: Pod>(s: &[Self]) -> Option<T>
Converts a POD slice into another type.
Returns None
if T
is larger.
Sourcefn merge_box<T: Pod>(s: Box<[Self]>) -> Result<Box<T>, Box<[Self]>>
fn merge_box<T: Pod>(s: Box<[Self]>) -> Result<Box<T>, Box<[Self]>>
Converts a boxed POD slice into another boxed type.
Fails if the types are misaligned or not the same size.
Sourcefn merge_vec<T: Pod>(s: Vec<Self>) -> Result<Box<T>, Vec<Self>>
fn merge_vec<T: Pod>(s: Vec<Self>) -> Result<Box<T>, Vec<Self>>
Converts a POD vector into another boxed type.
Fails if the types are misaligned or not the same size.
Sourceunsafe fn from_ptr<T>(source: *const T) -> Self
unsafe fn from_ptr<T>(source: *const T) -> Self
Creates a new POD instance from an unaligned pointer.
This is an unsafe operation because the pointer is not validated in any way.
Sourcefn from_ref<T: Pod>(p: &T) -> Option<Self>
fn from_ref<T: Pod>(p: &T) -> Option<Self>
Creates a new POD instance with the inverse of map_copy()
Sourcefn from_slice<T: Pod>(p: &[T]) -> Option<Self>
fn from_slice<T: Pod>(p: &[T]) -> Option<Self>
Creates a new POD instance with the inverse of merge_copy()
Sourcefn from_boxed_slice<T: Pod>(p: Box<[T]>) -> Result<Box<Self>, Box<[T]>>
fn from_boxed_slice<T: Pod>(p: Box<[T]>) -> Result<Box<Self>, Box<[T]>>
Creates a new POD instance with the inverse of merge_box()
Sourcefn from_vec<T: Pod>(p: Vec<T>) -> Result<Box<Self>, Vec<T>>
fn from_vec<T: Pod>(p: Vec<T>) -> Result<Box<Self>, Vec<T>>
Creates a new POD instance with the inverse of merge_vec()
Sourcefn slice_from_boxed_slice<T: Pod>(p: Box<[T]>) -> Result<Box<[Self]>, Box<[T]>>
fn slice_from_boxed_slice<T: Pod>(p: Box<[T]>) -> Result<Box<[Self]>, Box<[T]>>
Creates a new POD instance with the inverse of map_slice_box()
Sourcefn ref_from_mut<T: Pod>(p: &mut T) -> Option<&mut Self>
fn ref_from_mut<T: Pod>(p: &mut T) -> Option<&mut Self>
Creates a mutable POD reference with the inverse of map_mut()
Sourcefn ref_from_slice<T: Pod>(p: &[T]) -> Option<&Self>
fn ref_from_slice<T: Pod>(p: &[T]) -> Option<&Self>
Creates a POD reference with the inverse of merge()
Sourcefn ref_from_slice_mut<T: Pod>(p: &mut [T]) -> Option<&mut Self>
fn ref_from_slice_mut<T: Pod>(p: &mut [T]) -> Option<&mut Self>
Creates a mutable POD reference with the inverse of merge_mut()
Sourcefn as_bytes_mut(&mut self) -> &mut [u8] ⓘ
fn as_bytes_mut(&mut self) -> &mut [u8] ⓘ
Borrows the POD as a mutable byte slice
Sourcefn from_bytes(p: &[u8]) -> Option<Self>
fn from_bytes(p: &[u8]) -> Option<Self>
Safely creates a POD value from a potentially unaligned slice
Returns None
if slice.len()
is not the same as the type’s size
Sourcefn ref_from_bytes(p: &[u8]) -> Option<&Self>
fn ref_from_bytes(p: &[u8]) -> Option<&Self>
Borrows a new instance of the POD from a byte slice
Returns None
if slice.len()
is not the same as the type’s size
Sourcefn ref_from_bytes_mut(p: &mut [u8]) -> Option<&mut Self>
fn ref_from_bytes_mut(p: &mut [u8]) -> Option<&mut Self>
Borrows a mutable instance of the POD from a mutable byte slice
Returns None
if slice.len()
is not the same as the type’s size
Sourcefn from_byte_slice(p: Box<[u8]>) -> Result<Box<Self>, Box<[u8]>>
fn from_byte_slice(p: Box<[u8]>) -> Result<Box<Self>, Box<[u8]>>
Converts a boxed slice to a boxed instance of the POD type
Fails if slice.len()
is not the same as the type’s size
Sourcefn from_byte_vec(p: Vec<u8>) -> Result<Box<Self>, Vec<u8>>
fn from_byte_vec(p: Vec<u8>) -> Result<Box<Self>, Vec<u8>>
Converts a byte vector to a boxed instance of the POD type
Fails if vec.len()
is not the same as the type’s size
Sourcefn into_byte_slice(self: Box<Self>) -> Box<[u8]>
fn into_byte_slice(self: Box<Self>) -> Box<[u8]>
Converts a boxed POD to a boxed slice
Sourcefn as_aligned_mut<T: Pod + Aligned<Unaligned = Self>>(
&mut self,
) -> Option<&mut T>
fn as_aligned_mut<T: Pod + Aligned<Unaligned = Self>>( &mut self, ) -> Option<&mut T>
Safely borrows the aligned value mutably
See also: Aligned::from_unaligned_mut
Sourcefn from_unaligned_mut<T: Copy + Unaligned>(s: &mut T) -> Option<&mut Self>where
Self: Aligned<Unaligned = T>,
fn from_unaligned_mut<T: Copy + Unaligned>(s: &mut T) -> Option<&mut Self>where
Self: Aligned<Unaligned = T>,
Safely borrows the unaligned value mutably
See also: Aligned::from_unaligned_mut
Sourcefn from_unaligned<T: Copy + Unaligned>(s: T) -> Selfwhere
Self: Aligned<Unaligned = T>,
fn from_unaligned<T: Copy + Unaligned>(s: T) -> Selfwhere
Self: Aligned<Unaligned = T>,
Safely converts an unaligned value to its aligned equivalent
See also: Aligned::from_unaligned
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.