Skip to main content

UnalignedSlice

Struct UnalignedSlice 

Source
pub struct UnalignedSlice<'a, T> { /* private fields */ }
Expand description

A minimally functional span over a potentially unaligned slice of elements of type T.

Like &[T], this type guarantees that the memory [self.as_ptr(), self.as_ptr().add(self.len())) is valid for reads.

However, unlike &[T], the pointer Self::as_ptr is not guaranteed to be aligned to std::mem::align_of::<T>().

If the type T is Copy, then std::ptr::read_unaligned can be used on the valid memory region for this slice to access values of type T.

Implementations§

Source§

impl<'a, T> UnalignedSlice<'a, T>

Source

pub const unsafe fn new(ptr: *const T, len: usize) -> Self

Construct a new UnalignedSlice over the region [ptr, ptr.add(len)).

§Safety

The provided memory region must be valid for reading via std::ptr::read_unaligned for the duration of the associated lifetime.

Note that ptr need not be aligned to std::mem::align_of::<T>().

Argument ptr may be null if len == 0.

Source

pub const fn len(&self) -> usize

Return the number of elements of type T available for reading from Self::as_ptr.

Source

pub const fn is_empty(&self) -> bool

Return true only if the associated slice is empty.

Source

pub const fn as_ptr(&self) -> *const T

Return the base pointer of the slice.

NOTE: It is not guaranteed that the returned pointer is aligned!

Trait Implementations§

Source§

impl<T> AsUnaligned for UnalignedSlice<'_, T>

Source§

type Element = T

The element type of the slice.
Source§

fn as_unaligned(&self) -> UnalignedSlice<'_, T>

Return an UnalignedSlice view of self.
Source§

impl<T> Clone for UnalignedSlice<'_, T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Copy for UnalignedSlice<'_, T>

Source§

impl<'a, T: Debug> Debug for UnalignedSlice<'a, T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T, U> DistanceFunction<UnalignedSlice<'_, T>, UnalignedSlice<'_, U>> for Distance<T, U>
where T: 'static, U: 'static,

Source§

fn evaluate_similarity( &self, x: UnalignedSlice<'_, T>, y: UnalignedSlice<'_, U>, ) -> f32

Perform a distance computation between the left-hand and right-hand arguments.
Source§

impl<'a, T, const N: usize> From<&'a [T; N]> for UnalignedSlice<'a, T>

Source§

fn from(slice: &'a [T; N]) -> Self

Converts to this type from the input type.
Source§

impl<'a, T> From<&'a [T]> for UnalignedSlice<'a, T>

Source§

fn from(slice: &'a [T]) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<'a, T> !Send for UnalignedSlice<'a, T>

§

impl<'a, T> !Sync for UnalignedSlice<'a, T>

§

impl<'a, T> Freeze for UnalignedSlice<'a, T>

§

impl<'a, T> RefUnwindSafe for UnalignedSlice<'a, T>
where T: RefUnwindSafe,

§

impl<'a, T> Unpin for UnalignedSlice<'a, T>

§

impl<'a, T> UnsafeUnpin for UnalignedSlice<'a, T>

§

impl<'a, T> UnwindSafe for UnalignedSlice<'a, T>
where T: RefUnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.