Skip to main content

ConstBuffer

Struct ConstBuffer 

Source
pub struct ConstBuffer<const TSIZE: usize, T: Sized + Copy> { /* private fields */ }
Expand description

This struct allows for iterating over a fixed-length blocks of arrays, given a big chunk of arbitrary length array.

§Examples

Lets say that we have an array of 20 elements:

let data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20];

and now we want to process it in a block-by-block fashion, with each block having 7 elements. We can do this:

use osom_lib_arrays::fixed_array::{ConstBuffer, ConstFixedArray};

let data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20];

let mut bufferer = ConstBuffer::<7, _>::new();
let mut iterator = bufferer.buffer_const(&data);
assert_eq!(iterator.next(), Some(&[1, 2, 3, 4, 5, 6, 7]));
assert_eq!(iterator.next(), Some(&[8, 9, 10, 11, 12, 13, 14]));
assert_eq!(iterator.next(), None);

// The iterator is drained, but we still have remaining data:
let remaining: ConstFixedArray<7, _> = bufferer.release_const();
assert_eq!(remaining.as_slice_const(), &[15, 16, 17, 18, 19, 20]);

§Notes

The ConstBuffer is additionally const friendly, and thus is defined for T: Copy only. In particular it isn’t Drop.

Implementations§

Source§

impl<const TSIZE: usize, T: Sized + Copy> ConstBuffer<TSIZE, T>

Source

pub const fn new() -> Self

Creates a new, empty ConstBufferer.

Source

pub const fn buffer_const<'a>( &'a mut self, data: &'a [T], ) -> ConstBufferer<'a, TSIZE, T>

Returns a new ConstBufferer for the given data.

§Panics

The function will panic if the data length exceeds u32::MAX.

Source

pub const fn length(&self) -> Length

Returns the length of the data buffered in the ConstBuffer.

Source

pub const fn clone_const(&self) -> Self

Clones the ConstBuffer.

Source

pub const fn current_state_const(&self) -> &ConstFixedArray<TSIZE, T>

Returns a reference to the currently buffered data.

Source

pub const fn release_const(self) -> ConstFixedArray<TSIZE, T>

Releases the remaining data from the bufferer.

Trait Implementations§

Source§

impl<const TSIZE: usize, T: ReprC + Sized + Copy> ReprC for ConstBuffer<TSIZE, T>

Source§

const CHECK: ()

This field is used for const checks only.

Auto Trait Implementations§

§

impl<const TSIZE: usize, T> Freeze for ConstBuffer<TSIZE, T>
where T: Freeze,

§

impl<const TSIZE: usize, T> RefUnwindSafe for ConstBuffer<TSIZE, T>
where T: RefUnwindSafe,

§

impl<const TSIZE: usize, T> Send for ConstBuffer<TSIZE, T>
where T: Send,

§

impl<const TSIZE: usize, T> Sync for ConstBuffer<TSIZE, T>
where T: Sync,

§

impl<const TSIZE: usize, T> Unpin for ConstBuffer<TSIZE, T>
where T: Unpin,

§

impl<const TSIZE: usize, T> UnsafeUnpin for ConstBuffer<TSIZE, T>
where T: UnsafeUnpin,

§

impl<const TSIZE: usize, T> UnwindSafe for ConstBuffer<TSIZE, T>
where T: UnwindSafe,

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.