Trait IoBufferRefTrait

Source
pub(crate) trait IoBufferRefTrait<'a>: Sized {
    type SliceType<T: Copy + Sized + 'a>;
    type PointerType<T: Copy + Sized + 'a>;

    // Required methods
    fn from_slice(slice: Self::SliceType<u8>) -> Self;
    fn try_into_owned(self, alignment: usize) -> Result<IoBuffer>;
    fn len(&self) -> usize;
    fn as_ptr(&self) -> Self::PointerType<u8>;
    unsafe fn into_typed_slice<T: Copy + Sized>(self) -> Self::SliceType<T>;
    fn split_at(self, mid: usize) -> (Self, Self);
    fn into_ref(self) -> IoBufferRef<'a>;

    // Provided methods
    fn is_empty(&self) -> bool { ... }
    fn into_slice(self) -> Self::SliceType<u8> { ... }
}
Expand description

Common functions for both IoBufferRef and IoBufferMut.

Required Associated Types§

Source

type SliceType<T: Copy + Sized + 'a>

&[T] or &mut [T].

Source

type PointerType<T: Copy + Sized + 'a>

*const T or *mut T.

Required Methods§

Source

fn from_slice(slice: Self::SliceType<u8>) -> Self

Create a reference to a slice.

Source

fn try_into_owned(self, alignment: usize) -> Result<IoBuffer>

Create an owned IoBuffer with the same data (copied).

Source

fn len(&self) -> usize

Size in bytes.

Source

fn as_ptr(&self) -> Self::PointerType<u8>

Return the pointer to the start of the buffer.

Source

unsafe fn into_typed_slice<T: Copy + Sized>(self) -> Self::SliceType<T>

Turn this reference into a slice with the given element type.

§Safety

Caller must ensure that alignment and length requirements are met and that the resulting data is valid.

Source

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

Split the buffer at mid.

Return &self[..mid] and &self[mid..].

If mid > self.len(), return &self[..] and [].

Source

fn into_ref(self) -> IoBufferRef<'a>

Make this reference immutable.

Provided Methods§

Source

fn is_empty(&self) -> bool

Whether the length is 0.

Source

fn into_slice(self) -> Self::SliceType<u8>

Turn this reference into a slice.

References to IoBuffers must not be copied/cloned (so they can only be accessed once; they are considered volatile due to potential VM guest accesses), so this consumes the object.

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.

Implementors§

Source§

impl<'a> IoBufferRefTrait<'a> for IoBufferMut<'a>

Source§

type SliceType<T: Copy + Sized + 'a> = &'a mut [T]

Source§

type PointerType<T: Copy + Sized + 'a> = *mut T

Source§

impl<'a> IoBufferRefTrait<'a> for IoBufferRef<'a>

Source§

type SliceType<T: Copy + Sized + 'a> = &'a [T]

Source§

type PointerType<T: Copy + Sized + 'a> = *const T