Vec.
This trait enables retrieving elements and checking the vector’s length without
modifying the underlying storage.
Signature
Trait functions
get
Returns a storage path to the element at the specified index, orNone if out of bounds.
Vec.
This trait enables retrieving elements and checking the vector’s length without
modifying the underlying storage.
pub trait VecTrait
None if out of bounds.
fn get(self: T, index: u64) -> OptionElementType>>
use starknet::storage::{Vec, VecTrait, StoragePointerReadAccess};
#[storage]
struct Storage {
    numbers: Vec,
}
fn maybe_number(self: @ContractState, index: u64) -> Option {
    self.numbers.get(index).map(|ptr| ptr.read())
}
use starknet::storage::{Vec, VecTrait, StoragePointerReadAccess};
#[storage]
struct Storage {
    numbers: Vec,
}
fn get_number(self: @ContractState, index: u64) -> u256 {
    self.numbers.at(index).read()
}
fn at(self: T, index: u64) -> StoragePathElementType>
fn len(self: T) -> u64
use starknet::storage::{Vec, VecTrait};
#[storage]
struct Storage {
    numbers: Vec,
}
fn is_empty(self: @ContractState) -> bool {
    self.numbers.len() == 0
}
type ElementType;
Was this page helpful?