#[repr(C)]pub struct HeaderSlice<H, T> { /* private fields */ }Expand description
A dynamically-sized view into a contiguous header and trailing sequence.
Implementations§
Source§impl<H, T> HeaderSlice<H, T>
impl<H, T> HeaderSlice<H, T>
Sourcepub fn with_header<F, R>(header: H, f: F) -> Rwhere
F: for<'a> FnOnce(&'a Self) -> R,
pub fn with_header<F, R>(header: H, f: F) -> Rwhere
F: for<'a> FnOnce(&'a Self) -> R,
Returns the result of calling f on a shared header-slice starting with
header.
Sourcepub fn with_header_mut<F, R>(header: H, f: F) -> Rwhere
F: for<'a> FnOnce(&'a mut Self) -> R,
pub fn with_header_mut<F, R>(header: H, f: F) -> Rwhere
F: for<'a> FnOnce(&'a mut Self) -> R,
Returns the result of calling f on a mutable header-slice starting
with header.
Sourcepub fn from_header(header: &H) -> Option<&Self>
pub fn from_header(header: &H) -> Option<&Self>
Attempts to create a shared header-slice from just header.
The address of header must be at least aligned to T because the
empty slice component must be properly aligned.
If T has equal or greater alignment than H, unwrapping the returned
value is a no-op.
Sourcepub fn from_header_mut(header: &mut H) -> Option<&mut Self>
pub fn from_header_mut(header: &mut H) -> Option<&mut Self>
Attempts to create a mutable header-slice from just header.
The address of header must be at least aligned to T because the
empty slice component must be properly aligned.
If T has equal or greater alignment than H, unwrapping the returned
value is a no-op.
Sourcepub fn from_boxed_header(header: Box<H>) -> Result<Box<Self>, Box<H>>
pub fn from_boxed_header(header: Box<H>) -> Result<Box<Self>, Box<H>>
Attempts to create a boxed header-slice from just header.
The address of header must be at least aligned to T because the
empty slice component must be properly aligned.
If T has equal or greater alignment than H, unwrapping the returned
value is a no-op.
Sourcepub unsafe fn from_header_unchecked(header: &H) -> &Self
pub unsafe fn from_header_unchecked(header: &H) -> &Self
Create a shared header-slice from just header, without checking its
alignment.
§Safety
The address of header must be at least aligned to T because the
empty slice component must be properly aligned.
Sourcepub unsafe fn from_header_unchecked_mut(header: &mut H) -> &mut Self
pub unsafe fn from_header_unchecked_mut(header: &mut H) -> &mut Self
Create a mutable header-slice from just header, without checking its
alignment.
§Safety
The address of header must be at least aligned to T because the
empty slice component must be properly aligned.
Sourcepub unsafe fn from_boxed_header_unchecked(header: Box<H>) -> Box<Self>
pub unsafe fn from_boxed_header_unchecked(header: Box<H>) -> Box<Self>
Create a boxed header-slice from just header, without checking its
alignment.
§Safety
The address of header must be at least aligned to T because the
empty slice component must be properly aligned.
Sourcepub unsafe fn from_raw_parts<'a>(header: *const H, len: usize) -> &'a Self
pub unsafe fn from_raw_parts<'a>(header: *const H, len: usize) -> &'a Self
Forms a shared header-slice from a pointer and a length.
§Safety
Behavior is undefined if any of the following conditions are violated:
-
headerand any slice following it must be valid.-
headermust be non-null and aligned to the greater alignment betweenHandT. -
If
lenis non-zero, the slice followingheadermust be aligned toT. -
The entire memory range of spanning from the start of
headerto the end of the trailing slice must be contained within a single allocated object! Header-slices can never span across multiple allocated objects.
-
-
The memory referenced by the returned header-slice must not be mutated for the duration of lifetime
'a, except inside anUnsafeCell. -
The total size of the resulting header-slice must be no larger than
isize::MAX.
§Caveat
The lifetime for the returned slice is inferred from its usage. To prevent accidental misuse, it’s suggested to tie the lifetime to whichever source lifetime is safe in the context, such as by providing a helper function taking the lifetime of a host value for the slice, or by explicit annotation.
Sourcepub unsafe fn from_raw_parts_mut<'a>(header: *mut H, len: usize) -> &'a mut Self
pub unsafe fn from_raw_parts_mut<'a>(header: *mut H, len: usize) -> &'a mut Self
Forms a mutable header-slice from a pointer and a length.
§Safety
Behavior is undefined if any of the following conditions are violated:
-
headerand any slice following it must be valid.-
headermust be non-null and aligned to the greater alignment betweenHandT. -
If
lenis non-zero, the slice followingheadermust be aligned toT. -
The entire memory range of spanning from the start of
headerto the end of the trailing slice must be contained within a single allocated object! Header-slices can never span across multiple allocated objects.
-
-
The memory referenced by the returned header-slice must not be accessed through any other pointer (not derived from the return value) for the duration of lifetime
'a. Both read and write accesses are forbidden. -
The total size of the resulting header-slice must be no larger than
isize::MAX.
§Caveat
The lifetime for the returned slice is inferred from its usage. To prevent accidental misuse, it’s suggested to tie the lifetime to whichever source lifetime is safe in the context, such as by providing a helper function taking the lifetime of a host value for the slice, or by explicit annotation.
Sourcepub unsafe fn boxed_from_raw_parts(header: *mut H, len: usize) -> Box<Self>
pub unsafe fn boxed_from_raw_parts(header: *mut H, len: usize) -> Box<Self>
Forms a boxed header-slice from a pointer and a length.
§Safety
header must point to a header-slice with a slice of len items that
has been allocated by the global allocator.
Improper use can lead to:
-
A double-free if the function is called twice on the same raw pointer.
-
Mutable aliasing, which causes undefined behavior.
Sourcepub fn as_header(&self) -> &H
pub fn as_header(&self) -> &H
Returns a shared reference to the value preceding a slice of T in
memory.
Sourcepub fn as_header_mut(&mut self) -> &mut H
pub fn as_header_mut(&mut self) -> &mut H
Returns a mutable reference to the value preceding a slice of T in
memory.
Sourcepub fn as_slice(&self) -> &[T]
pub fn as_slice(&self) -> &[T]
Returns a shared reference to the trailing contiguous sequence of values.
Sourcepub fn as_slice_mut(&mut self) -> &mut [T]
pub fn as_slice_mut(&mut self) -> &mut [T]
Returns a mutable reference to the trailing contiguous sequence of values.
Sourcepub fn as_header_and_slice(&self) -> (&H, &[T])
pub fn as_header_and_slice(&self) -> (&H, &[T])
Returns shared references to the header and its proceeded slice of T.
Sourcepub fn as_header_and_slice_mut(&mut self) -> (&mut H, &mut [T])
pub fn as_header_and_slice_mut(&mut self) -> (&mut H, &mut [T])
Returns mutable references to the header and its proceeded slice of T.
Source§impl<H> HeaderSlice<H, H>
impl<H> HeaderSlice<H, H>
Sourcepub fn from_full_slice(slice: &[H]) -> Option<&Self>
pub fn from_full_slice(slice: &[H]) -> Option<&Self>
Attempts to create a shared header-slice from slice, using the first
element as the header.
Returns None if slice is empty.
Sourcepub fn from_full_slice_mut(slice: &mut [H]) -> Option<&mut Self>
pub fn from_full_slice_mut(slice: &mut [H]) -> Option<&mut Self>
Attempts to create a mutable header-slice from slice, using the first
element as the header.
Returns None if slice is empty.
Sourcepub fn from_full_boxed_slice(slice: Box<[H]>) -> Option<Box<Self>>
pub fn from_full_boxed_slice(slice: Box<[H]>) -> Option<Box<Self>>
Attempts to create a boxed header-slice from slice, using the first
element as the header.
Returns None if slice is empty.
Sourcepub unsafe fn from_full_slice_unchecked(slice: &[H]) -> &Self
pub unsafe fn from_full_slice_unchecked(slice: &[H]) -> &Self
Creates a shared header-slice from slice, using the first element as
the header without checking if it exists.
§Safety
slice must be non-empty.
Sourcepub unsafe fn from_full_slice_unchecked_mut(slice: &mut [H]) -> &mut Self
pub unsafe fn from_full_slice_unchecked_mut(slice: &mut [H]) -> &mut Self
Creates a mutable header-slice from slice, using the first element as
the header without checking if it exists.
§Safety
slice must be non-empty.
Sourcepub unsafe fn from_full_boxed_slice_unchecked(slice: Box<[H]>) -> Box<Self>
pub unsafe fn from_full_boxed_slice_unchecked(slice: Box<[H]>) -> Box<Self>
Creates a boxed header-slice from slice, using the first element as
the header without checking if it exists.
§Safety
slice must be non-empty.
Sourcepub fn as_full_slice(&self) -> &[H]
pub fn as_full_slice(&self) -> &[H]
Returns the full range of self as a single shared slice.
Sourcepub fn as_full_slice_mut(&mut self) -> &mut [H]
pub fn as_full_slice_mut(&mut self) -> &mut [H]
Returns the full range of self as a single mutable slice.
Sourcepub fn into_full_boxed_slice(self: Box<Self>) -> Box<[H]>
pub fn into_full_boxed_slice(self: Box<Self>) -> Box<[H]>
Returns the full range of self as a single boxed slice.