Struct kernel::utilities::leasable_buffer::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>
impl<'a, T> SubSliceMut<'a, T>
sourcepub fn new(buffer: &'a mut [T]) -> Self
pub fn new(buffer: &'a mut [T]) -> Self
Create a SubSlice from a passed reference to a raw buffer.
sourcepub fn take(self) -> &'a mut [T]
pub fn take(self) -> &'a mut [T]
Retrieve the raw buffer used to create the SubSlice. Consumes the SubSlice.
sourcepub fn reset(&mut self)
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.
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the length of the currently accessible portion of the SubSlice.
sourcepub fn as_ptr(&self) -> *const T
pub fn as_ptr(&self) -> *const T
Returns a pointer to the currently accessible portion of the SubSlice.
pub fn as_mut_ptr(&mut self) -> *mut T
sourcepub fn as_slice(&mut self) -> &mut [T]
pub fn as_slice(&mut self) -> &mut [T]
Returns a slice of the currently accessible portion of the LeasableBuffer.
sourcepub fn is_sliced(&self) -> bool
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.
sourcepub fn slice<R: RangeBounds<usize>>(&mut self, range: R)
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>
impl<'a, T: Debug> Debug for SubSliceMut<'a, T>
source§impl<'a, T> From<&'a mut [T]> for SubSliceMut<'a, T>
impl<'a, T> From<&'a mut [T]> for SubSliceMut<'a, T>
source§impl<'a, T, I> Index<I> for SubSliceMut<'a, T>where
I: SliceIndex<[T]>,
impl<'a, T, I> Index<I> for SubSliceMut<'a, T>where
I: SliceIndex<[T]>,
source§impl<'a, T, I> IndexMut<I> for SubSliceMut<'a, T>where
I: SliceIndex<[T]>,
impl<'a, T, I> IndexMut<I> for SubSliceMut<'a, T>where
I: SliceIndex<[T]>,
source§impl<'a, T: PartialEq> PartialEq for SubSliceMut<'a, T>
impl<'a, T: PartialEq> PartialEq for SubSliceMut<'a, T>
source§fn eq(&self, other: &SubSliceMut<'a, T>) -> bool
fn eq(&self, other: &SubSliceMut<'a, T>) -> bool
self
and other
values to be equal, and is used
by ==
.