Struct possibly_uninit::slice::Cursor [−][src]
Wraps a (maybe uninitialized) slice as a BorrowOutSlice
, tracking the
position. This allows you to work with readers and uninitialized memory
completely safely.
Note that this type doesn’t implement traits like Deref
, Borrow
,
AsRef
, BorrowUninitSlice
. This isn’t a gross negligence, it’s done on
purpose. Basically, it acts as if it contained two or even three
buffers! Which buffer should be returned? One might kinda reasonably claim
it should be first part for [Item] slices, second part for [MaybeUninit
This looks like a huge freaking footgun that I’m unwilling to create.
However I’d like to implement wrapper type in the future that will make it
explicit. E.g. something like Cursed<Written, T>
, Cursed<Uninit, T>
,
Cursed<Entire, T>
. :) PRs welcome!
Important: This wrapper currently doesn’t care about leaking! If you want
to avoid leaks, it’s recommended to use it only with buffers containing
MaybeUninit<T>
or with Copy
types.
This may change in future versions.
Implementations
impl<Item, Arr: BorrowOutSlice<Item>> Cursor<Item, Arr>
[src]
impl<Item, Arr: BorrowOutSlice<Item> + ?Sized> Cursor<Item, Arr>
[src]
pub fn push(&mut self, item: Item) -> Result<&mut Item, Item>
[src]
Pushes an item at the end of the array
pub fn push_iter<I>(&mut self, iter: I) -> &mut [Item] where
I: IntoIterator,
I::Item: TakeItem<Item>,
[src]
I: IntoIterator,
I::Item: TakeItem<Item>,
Pushes up to .remaining_count()
items from the iterator and returns a
subslice corresponding to just written items.
If you want to access everything that has been written so far, use the
written()
method after call to this one.
pub fn remaining_count(&self) -> usize
[src]
Returns the number of items that can be written to this cursor.
pub fn reset(&mut self)
[src]
Resets the position to 0.
pub fn written(&self) -> &[Item]
[src]
Access the written slice.
pub fn written_mut(&mut self) -> &mut [Item]
[src]
Mutably access the written slice.
pub fn pop(&mut self) -> Option<Item> where
Item: Copy,
[src]
Item: Copy,
Attempts to “remove” the last item and return it.
This can be implemented for Copy
types safely, as swapping the place with
uninitialized memory would cause corruption if the slice was actually
not MaybeUninit.
pub fn pop_slice(&mut self, max: usize) -> &mut [Item]
[src]
“Removes” up to max
slice from the buffer and returns them as slice.
Empty slice is returned if the position is zero, of course.
pub fn try_pop_slice(&mut self, required: usize) -> Option<&mut [Item]>
[src]
Attempts to “remove” required
number of slice from the buffer and
return them as slice. Keeps the cursor unchanged in case of failure.
Empty slice is returned if the position is zero, of course.
pub fn split_mut(&mut self) -> (&mut [Item], &mut OutSlice<Item>)
[src]
Splits the internal buffer at current position and returns both initialized and uninitialized part.
pub fn try_cast_initialized(self) -> Result<<Arr as InitTc<Item>>::Output, Self> where
Arr: Sized + InitTc<Item>,
[src]
Arr: Sized + InitTc<Item>,
Tries to cast the underlying data into initialized version of the container, if the entire slice was filled.
Trait Implementations
impl<Item, Arr: BorrowOutSlice<Item>> From<Arr> for Cursor<Item, Arr>
[src]
Auto Trait Implementations
impl<Item, Arr: ?Sized> Send for Cursor<Item, Arr> where
Arr: Send,
Item: Send,
Arr: Send,
Item: Send,
impl<Item, Arr: ?Sized> Sync for Cursor<Item, Arr> where
Arr: Sync,
Item: Sync,
Arr: Sync,
Item: Sync,
impl<Item, Arr: ?Sized> Unpin for Cursor<Item, Arr> where
Arr: Unpin,
Item: Unpin,
Arr: Unpin,
Item: Unpin,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> AnyValid for T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<!> for T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> PtrCount for T
[src]
type Item = T
Either Self or type of item in the slice.
pub fn ptr_count(&Self) -> (*const <T as PtrCount>::Item, usize)
[src]
pub fn ptr_count_mut(&mut Self) -> (*mut <T as PtrCount>::Item, usize)
[src]
fn as_slice(&self) -> &[Self::Item]
[src]
fn as_slice_mut(&mut self) -> &mut [Self::Item] where
Self: AnyValid,
[src]
Self: AnyValid,
impl<T> TakeItem<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,