Skip to main content

BoundedVec

Struct BoundedVec 

Source
pub struct BoundedVec<T, const N: usize>
where T: TailCodec + Copy + Default,
{ /* 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>
where T: TailCodec + Copy + Default,

Source

pub fn empty() -> BoundedVec<T, N>

Construct an empty bounded vector.

Source

pub fn from_slice(values: &[T]) -> Result<BoundedVec<T, N>, ProgramError>

Construct from a slice, rejecting values longer than N.

Source

pub fn push(&mut self, item: T) -> Result<(), ProgramError>

Push one item into the bounded vector.

Source

pub fn pop(&mut self) -> Option<T>

Pop the last initialized item, if present.

Source

pub fn clear(&mut self)

Clear all initialized items without changing capacity.

Source

pub fn as_slice(&self) -> &[T]

Return the initialized items.

Source

pub fn as_mut_slice(&mut self) -> &mut [T]

Return the initialized items mutably.

Source

pub const fn len(&self) -> usize

Number of initialized items.

Source

pub const fn capacity(&self) -> usize

Maximum number of items.

Source

pub const fn remaining_capacity(&self) -> usize

Remaining element capacity.

Source

pub const fn is_full(&self) -> bool

Whether the vector has reached its maximum element capacity.

Source

pub const fn is_empty(&self) -> bool

Whether the vector is empty.

Source§

impl<T, const N: usize> BoundedVec<T, N>

Source

pub fn contains(&self, item: &T) -> bool

Return true when the initialized items contain item.

Source

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.

Source

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>
where T: Clone + TailCodec + Copy + Default,

Source§

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)

Performs copy-assignment from source. Read more
Source§

impl<T, const N: usize> Default for BoundedVec<T, N>
where T: TailCodec + Copy + Default,

Source§

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>

Source§

fn eq(&self, other: &BoundedVec<T, N>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T, const N: usize> TailCodec for BoundedVec<T, N>
where T: TailCodec + Copy + Default,

Source§

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>

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>

Deserialize from input. Returns (value, bytes_consumed). Fails with InvalidAccountData on malformed encoding.
Source§

impl<T, const N: usize> Copy for BoundedVec<T, N>
where T: Copy + TailCodec + Default,

Source§

impl<T, const N: usize> Eq for BoundedVec<T, N>
where T: Eq + TailCodec + Copy + Default,

Source§

impl<T, const N: usize> StructuralPartialEq for BoundedVec<T, N>
where T: TailCodec + Copy + Default,

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> 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> TailElement for T