Trait zerocopy::SplitByteSlice

source ·
pub unsafe trait SplitByteSlice: ByteSlice {
    // Required method
    unsafe fn split_at_unchecked(self, mid: usize) -> (Self, Self);

    // Provided method
    fn split_at(self, mid: usize) -> (Self, Self) { ... }
}
Expand description

A ByteSlice that can be split in two.

§Safety

Unsafe code may depend for its soundness on the assumption that split_at and split_at_unchecked are implemented correctly. In particular, given B: SplitByteSlice and b: B, if b.deref() returns a byte slice with address addr and length len, then if split <= len, both of these invocations:

  • b.split_at(split)
  • b.split_at_unchecked(split)

…will return (first, second) such that:

  • first’s address is addr and its length is split
  • second’s address is addr + split and its length is len - split

Required Methods§

source

unsafe fn split_at_unchecked(self, mid: usize) -> (Self, Self)

Splits the slice at the midpoint, possibly omitting bounds checks.

x.split_at_unchecked(mid) returns x[..mid] and x[mid..].

§Safety

mid must not be greater than x.deref().len().

Provided Methods§

source

fn split_at(self, mid: usize) -> (Self, Self)

Splits the slice at the midpoint.

x.split_at(mid) returns x[..mid] and x[mid..].

§Panics

x.split_at(mid) panics if mid > x.deref().len().

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<'a> SplitByteSlice for &'a [u8]

source§

impl<'a> SplitByteSlice for &'a mut [u8]

source§

impl<'a> SplitByteSlice for Ref<'a, [u8]>

source§

impl<'a> SplitByteSlice for RefMut<'a, [u8]>

Implementors§