zerocopy::byte_slice

Trait ByteSlice

Source
pub unsafe trait ByteSlice: Deref<Target = [u8]> + Sized { }
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]>.

§Safety

Implementations of ByteSlice must promise that their implementations of [Deref] and [DerefMut] are “stable”. In particular, given B: ByteSlice and b: B, two calls, each to either b.deref() or b.deref_mut(), must return a byte slice with the same address and length. This must hold even if the two calls are separated by an arbitrary sequence of calls to methods on ByteSlice, ByteSliceMut, IntoByteSlice, or IntoByteSliceMut, or on their super-traits. This does not need to hold if the two calls are separated by any method calls, field accesses, or field modifications other than those from these traits.

Note that this also implies that, given b: B, the address and length cannot be modified via objects other than b, either on the same thread or on another thread.

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 ByteSlice for &[u8]

Source§

impl ByteSlice for &mut [u8]

Source§

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

Source§

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

Implementors§