pub struct BoundedVec<T, const N: usize>{ /* private fields */ }Expand description
Bounded dynamic vector for Hopper dynamic tails.
This is the common migration target for bounded vector account metadata.
Elements use TailCodec, so the vector can carry wire integers, addresses,
or small custom structs declared with hopper_dynamic_tail!.
Implementations§
Source§impl<T, const N: usize> BoundedVec<T, N>
impl<T, const N: usize> BoundedVec<T, N>
Sourcepub fn empty() -> BoundedVec<T, N>
pub fn empty() -> BoundedVec<T, N>
Construct an empty bounded vector.
Sourcepub fn from_slice(values: &[T]) -> Result<BoundedVec<T, N>, ProgramError>
pub fn from_slice(values: &[T]) -> Result<BoundedVec<T, N>, ProgramError>
Construct from a slice, rejecting values longer than N.
Sourcepub fn push(&mut self, item: T) -> Result<(), ProgramError>
pub fn push(&mut self, item: T) -> Result<(), ProgramError>
Push one item into the bounded vector.
Sourcepub fn as_mut_slice(&mut self) -> &mut [T]
pub fn as_mut_slice(&mut self) -> &mut [T]
Return the initialized items mutably.
Sourcepub const fn remaining_capacity(&self) -> usize
pub const fn remaining_capacity(&self) -> usize
Remaining element capacity.
Source§impl<T, const N: usize> BoundedVec<T, N>
impl<T, const N: usize> BoundedVec<T, N>
Sourcepub fn push_unique(&mut self, item: T) -> Result<bool, ProgramError>
pub fn push_unique(&mut self, item: T) -> Result<bool, ProgramError>
Push item only if it is not already initialized.
Returns Ok(true) when an item was inserted and Ok(false) when it
was already present.
Sourcepub fn remove_first(&mut self, item: &T) -> bool
pub fn remove_first(&mut self, item: &T) -> bool
Remove the first matching item, preserving order.
Returns true when an item was removed.
Trait Implementations§
Source§impl<T, const N: usize> Clone for BoundedVec<T, N>
impl<T, const N: usize> Clone for BoundedVec<T, N>
Source§fn clone(&self) -> BoundedVec<T, N>
fn clone(&self) -> BoundedVec<T, N>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<T, const N: usize> Default for BoundedVec<T, N>
impl<T, const N: usize> Default for BoundedVec<T, N>
Source§fn default() -> BoundedVec<T, N>
fn default() -> BoundedVec<T, N>
Returns the “default value” for a type. Read more
Source§impl<T, const N: usize> PartialEq for BoundedVec<T, N>
impl<T, const N: usize> PartialEq for BoundedVec<T, N>
Source§fn eq(&self, other: &BoundedVec<T, N>) -> bool
fn eq(&self, other: &BoundedVec<T, N>) -> bool
Tests for
self and other values to be equal, and is used by ==.Source§impl<T, const N: usize> TailCodec for BoundedVec<T, N>
impl<T, const N: usize> TailCodec for BoundedVec<T, N>
Source§const MAX_ENCODED_LEN: usize
const MAX_ENCODED_LEN: usize
Upper bound on the encoded size. Used by generated helpers to
verify the account has enough room before invoking
encode.
Implementors should pick the smallest valid bound. Hopper
uses this to pre-size reallocs.Source§fn encode(&self, out: &mut [u8]) -> Result<usize, ProgramError>
fn encode(&self, out: &mut [u8]) -> Result<usize, ProgramError>
Serialize
self into out. Returns the number of bytes
written (always <= MAX_ENCODED_LEN). Fails with
AccountDataTooSmall when out.len() < encoded_len.Source§fn decode(input: &[u8]) -> Result<(BoundedVec<T, N>, usize), ProgramError>
fn decode(input: &[u8]) -> Result<(BoundedVec<T, N>, usize), ProgramError>
Deserialize from
input. Returns (value, bytes_consumed).
Fails with InvalidAccountData on malformed encoding.impl<T, const N: usize> Copy for BoundedVec<T, N>
impl<T, const N: usize> Eq for BoundedVec<T, N>
impl<T, const N: usize> StructuralPartialEq for BoundedVec<T, N>
Auto Trait Implementations§
impl<T, const N: usize> Freeze for BoundedVec<T, N>where
T: Freeze,
impl<T, const N: usize> RefUnwindSafe for BoundedVec<T, N>where
T: RefUnwindSafe,
impl<T, const N: usize> Send for BoundedVec<T, N>where
T: Send,
impl<T, const N: usize> Sync for BoundedVec<T, N>where
T: Sync,
impl<T, const N: usize> Unpin for BoundedVec<T, N>where
T: Unpin,
impl<T, const N: usize> UnsafeUnpin for BoundedVec<T, N>where
T: UnsafeUnpin,
impl<T, const N: usize> UnwindSafe for BoundedVec<T, N>where
T: UnwindSafe,
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