kernel::utilities::leasable_buffer

Struct SubSliceMut

Source
pub struct SubSliceMut<'a, T> { /* private fields */ }
Expand description

A mutable leasable buffer implementation.

A leasable buffer can be used to pass a section of a larger mutable buffer but still get the entire buffer back in a callback.

Implementations§

Source§

impl<'a, T> SubSliceMut<'a, T>

Source

pub fn new(buffer: &'a mut [T]) -> Self

Create a SubSlice from a passed reference to a raw buffer.

Source

pub fn take(self) -> &'a mut [T]

Retrieve the raw buffer used to create the SubSlice. Consumes the SubSlice.

Source

pub fn reset(&mut self)

Resets the SubSlice to its full size, making the entire buffer accessible again.

This should only be called by layer that created the SubSlice, and not layers that were passed a SubSlice. Layers which are using a SubSlice should treat the SubSlice as a traditional Rust slice and not consider any additional size to the underlying buffer.

Most commonly, this is called once a sliced leasable buffer is returned through a callback.

Source

pub fn len(&self) -> usize

Returns the length of the currently accessible portion of the SubSlice.

Source

pub fn as_ptr(&self) -> *const T

Returns a pointer to the currently accessible portion of the SubSlice.

Source

pub fn as_mut_ptr(&mut self) -> *mut T

Source

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

Returns a slice of the currently accessible portion of the LeasableBuffer.

Source

pub fn is_sliced(&self) -> bool

Returns true if the LeasableBuffer is sliced internally.

This is a useful check when switching between code that uses LeasableBuffers and code that uses traditional slice-and-length. Since slice-and-length only supports using the entire buffer it is not valid to try to use a sliced LeasableBuffer.

Source

pub fn slice<R: RangeBounds<usize>>(&mut self, range: R)

Reduces the range of the SubSlice that is accessible.

This should be called whenever a layer wishes to pass only a portion of a larger buffer to another layer.

For example, if the application layer has a 1500 byte packet buffer, but wishes to send a 250 byte packet, the upper layer should slice the SubSlice down to its first 250 bytes before passing it down:

let buffer = static_init!([u8; 1500], [0; 1500]);
let s = SubSliceMut::new(buffer);
s.slice(0..250);
network.send(s);

Trait Implementations§

Source§

impl<'a, T: Debug> Debug for SubSliceMut<'a, T>

Source§

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

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

impl<'a, T> From<&'a mut [T]> for SubSliceMut<'a, T>

Source§

fn from(internal: &'a mut [T]) -> Self

Converts to this type from the input type.
Source§

impl<T, I> Index<I> for SubSliceMut<'_, T>
where I: SliceIndex<[T]>,

Source§

type Output = <I as SliceIndex<[T]>>::Output

The returned type after indexing.
Source§

fn index(&self, idx: I) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<T, I> IndexMut<I> for SubSliceMut<'_, T>
where I: SliceIndex<[T]>,

Source§

fn index_mut(&mut self, idx: I) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<'a, T: PartialEq> PartialEq for SubSliceMut<'a, T>

Source§

fn eq(&self, other: &SubSliceMut<'a, 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<'a, T> StructuralPartialEq for SubSliceMut<'a, T>

Auto Trait Implementations§

§

impl<'a, T> Freeze for SubSliceMut<'a, T>

§

impl<'a, T> RefUnwindSafe for SubSliceMut<'a, T>
where T: RefUnwindSafe,

§

impl<'a, T> Send for SubSliceMut<'a, T>
where T: Send,

§

impl<'a, T> Sync for SubSliceMut<'a, T>
where T: Sync,

§

impl<'a, T> Unpin for SubSliceMut<'a, T>

§

impl<'a, T> !UnwindSafe for SubSliceMut<'a, T>

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
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.