VecTrait
Provides read-only access to elements in a storage Vec
.This trait enables retrieving elements and checking the vector's length without modifying the underlying storage.
Fully qualified path: core::starknet::storage::vec::VecTrait
pub trait VecTrait<T>
Trait functions
get
Returns a storage path to the element at the specified index, or None
if out of bounds. # Examples
use starknet::storage::{Vec, VecTrait, StoragePointerReadAccess};
[storage]
struct Storage {
numbers: Vec<u256>,
}
fn maybe_number(self: @ContractState, index: u64) -> Option<u256> {
self.numbers.get(index).map(|ptr| ptr.read())
}
Fully qualified path: core::starknet::storage::vec::VecTrait::get
fn get(self: T, index: u64) -> Option<StoragePath<Self::ElementType>>
at
Returns a storage path to access the element at the specified index. # PanicsPanics if the index is out of bounds. # Examples
use starknet::storage::{Vec, VecTrait, StoragePointerReadAccess};
[storage]
struct Storage {
numbers: Vec<u256>,
}
fn get_number(self: @ContractState, index: u64) -> u256 {
self.numbers.at(index).read()
}
Fully qualified path: core::starknet::storage::vec::VecTrait::at
fn at(self: T, index: u64) -> StoragePath<Self::ElementType>
len
Returns the number of elements in the vector.The length is stored at the vector's base storage address and is automatically updated when elements are appended. # Examples
use starknet::storage::{Vec, VecTrait};
[storage]
struct Storage {
numbers: Vec<u256>,
}
fn is_empty(self: @ContractState) -> bool {
self.numbers.len() == 0
}
Fully qualified path: core::starknet::storage::vec::VecTrait::len
fn len(self: T) -> u64
Trait types
ElementType
Fully qualified path: core::starknet::storage::vec::VecTrait::ElementType
type ElementType;