pub struct FixedVec<'a, T: Pod + FixedLayout> { /* private fields */ }Expand description
Bounded dynamic array overlaid on a byte slice.
Supports O(1) push, O(1) pop, O(1) swap_remove, O(1) index access. No heap allocation.
Implementations§
Source§impl<'a, T: Pod + FixedLayout> FixedVec<'a, T>
impl<'a, T: Pod + FixedLayout> FixedVec<'a, T>
Sourcepub fn from_bytes(data: &'a mut [u8]) -> Result<Self, ProgramError>
pub fn from_bytes(data: &'a mut [u8]) -> Result<Self, ProgramError>
Overlay a FixedVec on a mutable byte slice.
The slice must be at least HEADER_SIZE bytes.
Capacity is (data.len() - HEADER_SIZE) / T::SIZE.
Sourcepub fn get(&self, index: usize) -> Result<T, ProgramError>
pub fn get(&self, index: usize) -> Result<T, ProgramError>
Read element at index (copy).
Sourcepub fn get_ref(&self, index: usize) -> Result<&T, ProgramError>
pub fn get_ref(&self, index: usize) -> Result<&T, ProgramError>
Get immutable reference to element at index.
Sourcepub fn set(&mut self, index: usize, value: T) -> Result<(), ProgramError>
pub fn set(&mut self, index: usize, value: T) -> Result<(), ProgramError>
Set element at index.
Sourcepub fn push(&mut self, value: T) -> Result<(), ProgramError>
pub fn push(&mut self, value: T) -> Result<(), ProgramError>
Push an element to the end. Returns error if at capacity.
Sourcepub fn pop(&mut self) -> Result<T, ProgramError>
pub fn pop(&mut self) -> Result<T, ProgramError>
Pop the last element.
Sourcepub fn swap_remove(&mut self, index: usize) -> Result<T, ProgramError>
pub fn swap_remove(&mut self, index: usize) -> Result<T, ProgramError>
Remove element at index by swapping with the last element. O(1).
Sourcepub const fn required_bytes(capacity: usize) -> usize
pub const fn required_bytes(capacity: usize) -> usize
Compute the byte size needed for a FixedVec with the given capacity.
Auto Trait Implementations§
impl<'a, T> Freeze for FixedVec<'a, T>
impl<'a, T> RefUnwindSafe for FixedVec<'a, T>where
T: RefUnwindSafe,
impl<'a, T> Send for FixedVec<'a, T>where
T: Send,
impl<'a, T> Sync for FixedVec<'a, T>where
T: Sync,
impl<'a, T> Unpin for FixedVec<'a, T>where
T: Unpin,
impl<'a, T> UnsafeUnpin for FixedVec<'a, T>
impl<'a, T> !UnwindSafe for FixedVec<'a, T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more