zerocopy

Trait ByteSlice

Source
pub unsafe trait ByteSlice:
    Deref<Target = [u8]>
    + Sized
    + ByteSliceSealed {
    // Required method
    fn split_at(self, mid: usize) -> (Self, Self);

    // Provided method
    fn as_ptr(&self) -> *const u8 { ... }
}
Expand description

A mutable or immutable reference to a byte slice.

ByteSlice abstracts over the mutability of a byte slice reference, and is implemented for various special reference types such as Ref<[u8]> and RefMut<[u8]>.

Note that, while it would be technically possible, ByteSlice is not implemented for Vec<u8>, as the only way to implement the split_at method would involve reallocation, and split_at must be a very cheap operation in order for the utilities in this crate to perform as designed.

Required 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.len().

Provided Methods§

Source

fn as_ptr(&self) -> *const u8

Gets a raw pointer to the first byte in the slice.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Implementors§