array_init_cursor

Struct Cursor

Source
pub struct Cursor<'a, T, const N: usize> { /* private fields */ }
Expand description

A fixed-size cursor for initializing MaybeUninit arrays

The cursor will guarantee that all values have been initialized when the value is dropped, which means that it is safe to call MaybeUninit::assume_init().

NOTE: This guarantee only holds as long as Drop::drop() is called. If the value goes out of scope without drop being called (e.g. because of core::mem::forget()), then this guarantee no longer applies.

Implementations§

Source§

impl<'a, T, const N: usize> Cursor<'a, T, N>

Source

pub fn new(slice: &'a mut [MaybeUninit<T>; N]) -> Self

Creates a new cursor.

Source

pub fn finish(self, value: [T; N])

Finishes the buffer by writing the remaining values.

This is equivalent to calling self.write::<N, 0>(value), except it is slightly more ergonomic.

Source

pub fn write<const L: usize, const R: usize>( self, value: [T; L], ) -> Cursor<'a, T, R>

Writes L values to the buffer and returns a new cursor for the remaining R values.

This function cannot compile unless L + R == N, however it will be able to pass through cargo check, since the error is not discovered by rustc until it tries to instantiate the code.

Source

pub fn split<const L: usize, const R: usize>( self, ) -> (Cursor<'a, T, L>, Cursor<'a, T, R>)

Splits the cursor in two.

This function cannot compile unless L + R == N, however it will be able to pass through cargo check, since the error is not discovered by rustc until it tries to instantiate the code.

Source

pub fn assert_size<const M: usize>(self) -> Cursor<'a, T, M>

Compile-time assertion that N == M to work-around limitations in rust generics.

This is useful if a type-signature requires the function to have a generic size argument, but you want compile-time errors when called with the wrong parameter.

§Examples
fn example<const N: usize>(cursor: array_init_cursor::Cursor<'_, u8, N>) {
    let cursor: array_init_cursor::Cursor<u8, 10> = cursor.assert_size();
}

Trait Implementations§

Source§

impl<'a, T, const N: usize> Drop for Cursor<'a, T, N>

Source§

fn drop(&mut self)

Will panic unless cursor has been completely initialized

Auto Trait Implementations§

§

impl<'a, T, const N: usize> Freeze for Cursor<'a, T, N>

§

impl<'a, T, const N: usize> RefUnwindSafe for Cursor<'a, T, N>
where T: RefUnwindSafe,

§

impl<'a, T, const N: usize> Send for Cursor<'a, T, N>
where T: Send,

§

impl<'a, T, const N: usize> Sync for Cursor<'a, T, N>
where T: Sync,

§

impl<'a, T, const N: usize> Unpin for Cursor<'a, T, N>

§

impl<'a, T, const N: usize> !UnwindSafe for Cursor<'a, T, N>

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.