HeaderSlice

Struct HeaderSlice 

Source
#[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>

Source

pub fn with_header<F, R>(header: H, f: F) -> R
where F: for<'a> FnOnce(&'a Self) -> R,

Returns the result of calling f on a shared header-slice starting with header.

Source

pub fn with_header_mut<F, R>(header: H, f: F) -> R
where F: for<'a> FnOnce(&'a mut Self) -> R,

Returns the result of calling f on a mutable header-slice starting with header.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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:

  • header and any slice following it must be valid.

    • header must be non-null and aligned to the greater alignment between H and T.

    • If len is non-zero, the slice following header must be aligned to T.

    • The entire memory range of spanning from the start of header to 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 an UnsafeCell.

  • 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.

Source

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:

  • header and any slice following it must be valid.

    • header must be non-null and aligned to the greater alignment between H and T.

    • If len is non-zero, the slice following header must be aligned to T.

    • The entire memory range of spanning from the start of header to 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.

Source

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.

Source

pub fn as_header(&self) -> &H

Returns a shared reference to the value preceding a slice of T in memory.

Source

pub fn as_header_mut(&mut self) -> &mut H

Returns a mutable reference to the value preceding a slice of T in memory.

Source

pub fn as_slice(&self) -> &[T]

Returns a shared reference to the trailing contiguous sequence of values.

Source

pub fn as_slice_mut(&mut self) -> &mut [T]

Returns a mutable reference to the trailing contiguous sequence of values.

Source

pub fn as_header_and_slice(&self) -> (&H, &[T])

Returns shared references to the header and its proceeded slice of T.

Source

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>

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn as_full_slice(&self) -> &[H]

Returns the full range of self as a single shared slice.

Source

pub fn as_full_slice_mut(&mut self) -> &mut [H]

Returns the full range of self as a single mutable slice.

Source

pub fn into_full_boxed_slice(self: Box<Self>) -> Box<[H]>

Returns the full range of self as a single boxed slice.

Trait Implementations§

Source§

impl<H: Debug, T: Debug> Debug for HeaderSlice<H, T>

Source§

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

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

impl<'a, H> From<&'a H> for &'a HeaderSlice<H, H>

Source§

fn from(header: &'a H) -> Self

Converts to this type from the input type.
Source§

impl<'a, H> From<&'a mut H> for &'a mut HeaderSlice<H, H>

Source§

fn from(header: &'a mut H) -> Self

Converts to this type from the input type.
Source§

impl<H> From<Box<H>> for Box<HeaderSlice<H, H>>

Source§

fn from(header: Box<H>) -> Self

Converts to this type from the input type.
Source§

impl<H: Hash, T: Hash> Hash for HeaderSlice<H, T>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
Source§

impl<H: Ord, T: Ord> Ord for HeaderSlice<H, T>

Source§

fn cmp(&self, other: &HeaderSlice<H, T>) -> Ordering

This method returns an Ordering between self and other. Read more
Source§

impl<H: PartialEq, T: PartialEq> PartialEq for HeaderSlice<H, T>

Source§

fn eq(&self, other: &HeaderSlice<H, T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<H: PartialOrd, T: PartialOrd> PartialOrd for HeaderSlice<H, T>

Source§

fn partial_cmp(&self, other: &HeaderSlice<H, T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<H: Eq, T: Eq> Eq for HeaderSlice<H, T>

Source§

impl<H, T> StructuralPartialEq for HeaderSlice<H, T>

Auto Trait Implementations§

§

impl<H, T> Freeze for HeaderSlice<H, T>
where H: Freeze, T: Freeze,

§

impl<H, T> RefUnwindSafe for HeaderSlice<H, T>

§

impl<H, T> Send for HeaderSlice<H, T>
where H: Send, T: Send,

§

impl<H, T> !Sized for HeaderSlice<H, T>

§

impl<H, T> Sync for HeaderSlice<H, T>
where H: Sync, T: Sync,

§

impl<H, T> Unpin for HeaderSlice<H, T>
where H: Unpin, T: Unpin,

§

impl<H, T> UnwindSafe for HeaderSlice<H, T>
where H: UnwindSafe, T: UnwindSafe,

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