[−][src]Struct fixed_slice_vec::vec::FixedSliceVec
Vec-like structure backed by a storage slice of possibly uninitialized data.
The maximum length (the capacity) is fixed at runtime to the length of the provided storage slice.
Methods
impl<'a, T: Sized + Copy> FixedSliceVec<'a, T>
[src]
pub fn new(storage: &'a mut [MaybeUninit<T>]) -> Self
[src]
Create a SliceVec backed by a slice of possibly-uninitialized data. The backing storage slice is used as capacity for Vec-like operations,
The initial length of the SliceVec is 0.
pub fn from_bytes(bytes: &'a mut [u8]) -> FixedSliceVec<'a, T>
[src]
Create a well-aligned SliceVec backed by a slice of the provided bytes. The slice is as large as possible given the item type and alignment of the provided bytes.
If you are interested in recapturing the prefix and suffix bytes on
either side of the carved-out SliceVec buffer, consider using align_from_bytes
instead:
let vec = fixed_slice_vec::FixedSliceVec::from_bytes(&mut bytes[..]);
The bytes are treated as if they might be uninitialized, so even if T
is u8
,
the length of the returned SliceVec
will be zero.
pub fn from_uninit_bytes(
bytes: &'a mut [MaybeUninit<u8>]
) -> FixedSliceVec<'a, T>
[src]
bytes: &'a mut [MaybeUninit<u8>]
) -> FixedSliceVec<'a, T>
Create a well-aligned SliceVec backed by a slice of the provided uninitialized bytes. The typed slice is as large as possible given its item type and the alignment of the provided bytes.
If you are interested in recapturing the prefix and suffix bytes on
either side of the carved-out SliceVec buffer, consider using align_from_uninit_bytes
:
pub fn align_from_bytes(
bytes: &'a mut [u8]
) -> (&'a mut [u8], FixedSliceVec<'a, T>, &'a mut [u8])
[src]
bytes: &'a mut [u8]
) -> (&'a mut [u8], FixedSliceVec<'a, T>, &'a mut [u8])
Create a well-aligned SliceVec backed by a slice of the provided bytes. The slice is as large as possible given the item type and alignment of the provided bytes. Returns the unused prefix and suffix bytes on either side of the carved-out SliceVec.
let mut bytes = [3u8, 1, 4, 1, 5, 9]; let (prefix, vec, suffix) = fixed_slice_vec::FixedSliceVec::align_from_bytes(&mut bytes[..]); let vec: fixed_slice_vec::FixedSliceVec<u16> = vec;
The bytes are treated as if they might be uninitialized, so even if T
is u8
,
the length of the returned SliceVec
will be zero.
pub fn align_from_uninit_bytes(
bytes: &'a mut [MaybeUninit<u8>]
) -> (&'a mut [MaybeUninit<u8>], FixedSliceVec<'a, T>, &'a mut [MaybeUninit<u8>])
[src]
bytes: &'a mut [MaybeUninit<u8>]
) -> (&'a mut [MaybeUninit<u8>], FixedSliceVec<'a, T>, &'a mut [MaybeUninit<u8>])
Create a well-aligned SliceVec backed by a slice of the provided bytes. The slice is as large as possible given the item type and alignment of the provided bytes. Returns the unused prefix and suffix bytes on either side of the carved-out SliceVec.
let mut bytes: [MaybeUninit<u8>; 15] = unsafe { MaybeUninit::uninit().assume_init() }; let (prefix, vec, suffix) = fixed_slice_vec::FixedSliceVec::align_from_uninit_bytes(&mut bytes[..]); let vec: fixed_slice_vec::FixedSliceVec<u16> = vec;
The length of the returned SliceVec
will be zero.
pub fn len(&self) -> usize
[src]
The length of the SliceVec. The number of initialized values that have been added to it.
pub fn capacity(&self) -> usize
[src]
The maximum amount of items that can live in this SliceVec
pub fn is_empty(&self) -> bool
[src]
Returns true if there are no items present.
pub fn is_full(&self) -> bool
[src]
Returns true if the SliceVec is full to capacity.
pub fn try_push(&mut self, value: T) -> Result<(), TryPushError<T>>
[src]
Attempt to add a value to the SliceVec.
Returns an error if there is not enough capacity to hold another item.
pub fn push(&mut self, value: T)
[src]
Attempt to add a value to the SliceVec.
Panics
Panics if there is not sufficient capacity to hold another item.
pub fn pop(&mut self) -> Option<T>
[src]
Remove the last item from the SliceVec.
pub fn clear(&mut self)
[src]
Removes the SliceVec's tracking of all items in it while retaining the same capacity. Note the utter lack of an attempt to drop any of the now-inaccessible slice content. Should be safe because we presently limit the item type to Copy types.
pub fn as_slice(&self) -> &[T]
[src]
Obtain an immutable slice view on the initialized portion of the SliceVec.
pub fn as_mut_slice(&mut self) -> &mut [T]
[src]
Obtain a mutable slice view on the initialized portion of the SliceVec.
Trait Implementations
impl<'a, T: Sized + Copy> AsMut<[T]> for FixedSliceVec<'a, T>
[src]
impl<'a, T: Sized + Copy> AsRef<[T]> for FixedSliceVec<'a, T>
[src]
impl<'a, T: Sized + Copy> Borrow<[T]> for FixedSliceVec<'a, T>
[src]
impl<'a, T: Sized + Copy> BorrowMut<[T]> for FixedSliceVec<'a, T>
[src]
fn borrow_mut(&mut self) -> &mut [T]
[src]
impl<'a, T: Sized + Copy> Debug for FixedSliceVec<'a, T> where
T: Debug,
[src]
T: Debug,
impl<'a, T: Sized + Copy> Deref for FixedSliceVec<'a, T>
[src]
impl<'a, T: Sized + Copy> DerefMut for FixedSliceVec<'a, T>
[src]
impl<'a, T: Sized + Copy> Eq for FixedSliceVec<'a, T> where
T: Eq,
[src]
T: Eq,
impl<'a, T: Sized + Copy> From<&'a mut [MaybeUninit<T>]> for FixedSliceVec<'a, T>
[src]
fn from(v: &'a mut [MaybeUninit<T>]) -> Self
[src]
impl<'a, T: Sized + Copy> From<&'a mut [T]> for FixedSliceVec<'a, T>
[src]
impl<'a, T: Sized + Copy> Hash for FixedSliceVec<'a, T> where
T: Hash,
[src]
T: Hash,
fn hash<H: Hasher>(&self, state: &mut H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<'a, T: Sized + Copy> PartialEq<[T]> for FixedSliceVec<'a, T> where
T: PartialEq,
[src]
T: PartialEq,
impl<'a, T: Sized + Copy> PartialEq<FixedSliceVec<'a, T>> for FixedSliceVec<'a, T> where
T: PartialEq,
[src]
T: PartialEq,
impl<'a, T: Sized + Copy> PartialOrd<FixedSliceVec<'a, T>> for FixedSliceVec<'a, T> where
T: PartialOrd,
[src]
T: PartialOrd,
Auto Trait Implementations
impl<'a, T> Send for FixedSliceVec<'a, T> where
T: Send,
T: Send,
impl<'a, T> Sync for FixedSliceVec<'a, T> where
T: Sync,
T: Sync,
impl<'a, T> Unpin for FixedSliceVec<'a, T>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut 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, 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.
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>,