Struct safe_transmute::error::UnalignedError
source · pub struct UnalignedError<'a, S, T> {
pub offset: usize,
pub source: &'a [S],
/* private fields */
}
Expand description
Unaligned memory access error.
Returned when the given data slice is not properly aligned for the target
type. It would have been properly aligned if offset
bytes were shifted
(discarded) from the front of the slice.
Fields§
§offset: usize
The required amount of bytes to discard at the front for the attempted transmutation to be successful.
source: &'a [S]
A slice of the original source data.
Implementations§
source§impl<'a, S, T> UnalignedError<'a, S, T>
impl<'a, S, T> UnalignedError<'a, S, T>
pub fn new(offset: usize, source: &'a [S]) -> Self
sourcepub unsafe fn copy_unchecked(&self) -> Vec<T>
pub unsafe fn copy_unchecked(&self) -> Vec<T>
Create a copy of the source data, transmuted into a vector. As the
vector will be properly aligned for accessing values of type T
, this
operation will not fail due to memory alignment constraints.
§Safety
The byte data in the slice needs to correspond to a valid contiguous
sequence of T
values.
sourcepub fn copy(&self) -> Vec<T>where
T: TriviallyTransmutable,
pub fn copy(&self) -> Vec<T>where
T: TriviallyTransmutable,
Create a copy of the source data, transmuted into a vector. As T
is
trivially transmutable, and the vector will be properly allocated
for accessing values of type T
, this operation is safe and will never
fail.
Trait Implementations§
source§impl<'a, S: Clone, T: Clone> Clone for UnalignedError<'a, S, T>
impl<'a, S: Clone, T: Clone> Clone for UnalignedError<'a, S, T>
source§fn clone(&self) -> UnalignedError<'a, S, T>
fn clone(&self) -> UnalignedError<'a, S, T>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<'a, S, T> Debug for UnalignedError<'a, S, T>
impl<'a, S, T> Debug for UnalignedError<'a, S, T>
source§impl<'a, S, T> Display for UnalignedError<'a, S, T>
impl<'a, S, T> Display for UnalignedError<'a, S, T>
source§impl<'a, S, T> Error for UnalignedError<'a, S, T>
impl<'a, S, T> Error for UnalignedError<'a, S, T>
source§fn description(&self) -> &str
fn description(&self) -> &str
1.30.0 · source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
source§impl<'a, S, T> From<UnalignedError<'a, S, T>> for Error<'a, S, T>
impl<'a, S, T> From<UnalignedError<'a, S, T>> for Error<'a, S, T>
source§fn from(o: UnalignedError<'a, S, T>) -> Self
fn from(o: UnalignedError<'a, S, T>) -> Self
source§impl<'a, S: PartialEq, T: PartialEq> PartialEq for UnalignedError<'a, S, T>
impl<'a, S: PartialEq, T: PartialEq> PartialEq for UnalignedError<'a, S, T>
source§fn eq(&self, other: &UnalignedError<'a, S, T>) -> bool
fn eq(&self, other: &UnalignedError<'a, S, T>) -> bool
self
and other
values to be equal, and is used
by ==
.