Struct soroban_sdk::Vec
source · [−]#[repr(transparent)]pub struct Vec<T>(_, _);
Expand description
Vec is a contiguous growable array type.
The array is stored in the Host and available to the Guest through the functions defined on Vec. Values stored in the Vec are transmitted to the Host as RawVals, and when retrieved from the Vec are transmitted back and converted from RawVal back into their type.
The values in a Vec are not guaranteed to be of type T
and conversion will
fail if they are not. Most functions on Vec return a Result
due to this.
To store u8
s and binary data, use Binary instead.
Vec values can be stored as ContractData, or in other types like Vec, Map, etc.
Examples
use soroban_sdk::{Binary, Env, vec};
let env = Env::default();
let vec = vec![&env, 0, 1, 2, 3];
assert_eq!(vec.len(), 4);
Implementations
sourceimpl<T> Vec<T> where
T: IntoVal<Env, RawVal> + TryFromVal<Env, RawVal>,
impl<T> Vec<T> where
T: IntoVal<Env, RawVal> + TryFromVal<Env, RawVal>,
pub fn new(env: &Env) -> Vec<T>
pub fn from_array<const N: usize>(env: &Env, items: [T; N]) -> Vec<T>
pub fn from_slice(env: &Env, items: &[T]) -> Vec<T> where
T: Clone,
pub fn get(&self, i: u32) -> Option<Result<T, T::Error>>
pub fn get_unchecked(&self, i: u32) -> Result<T, T::Error> where
T::Error: Debug,
pub fn set(&mut self, i: u32, v: T)
pub fn remove(&mut self, i: u32) -> Option<()>
pub fn remove_unchecked(&mut self, i: u32)
pub fn is_empty(&self) -> bool
pub fn len(&self) -> u32
pub fn push(&mut self, x: T)
pub fn pop(&mut self) -> Option<Result<T, T::Error>>
pub fn pop_unchecked(&mut self) -> Result<T, T::Error>
pub fn first(&self) -> Option<Result<T, T::Error>>
pub fn first_unchecked(&self) -> Result<T, T::Error>
pub fn last(&self) -> Option<Result<T, T::Error>>
pub fn last_unchecked(&self) -> Result<T, T::Error>
pub fn insert(&mut self, i: u32, x: T)
pub fn append(&mut self, other: &Vec<T>)
pub fn extend_from_array<const N: usize>(&mut self, items: [T; N])
pub fn extend_from_slice(&mut self, items: &[T]) where
T: Clone,
pub fn slice(&self, r: impl RangeBounds<u32>) -> Self
pub fn iter(&self) -> VecIter<T> where
T: IntoVal<Env, RawVal> + TryFromVal<Env, RawVal> + Clone,
pub fn iter_unchecked(&self) -> UncheckedIter<VecIter<T>, T, T::Error>ⓘNotable traits for UncheckedIter<I, T, E>impl<I, T, E> Iterator for UncheckedIter<I, T, E> where
I: Iterator<Item = Result<T, E>>,
E: Debug, type Item = T;
where
T: IntoVal<Env, RawVal> + TryFromVal<Env, RawVal> + Clone,
T::Error: Debug,
I: Iterator<Item = Result<T, E>>,
E: Debug, type Item = T;
pub fn into_iter_unchecked(self) -> UncheckedIter<VecIter<T>, T, T::Error>ⓘNotable traits for UncheckedIter<I, T, E>impl<I, T, E> Iterator for UncheckedIter<I, T, E> where
I: Iterator<Item = Result<T, E>>,
E: Debug, type Item = T;
where
T: IntoVal<Env, RawVal> + TryFromVal<Env, RawVal> + Clone,
T::Error: Debug,
I: Iterator<Item = Result<T, E>>,
E: Debug, type Item = T;
Trait Implementations
sourceimpl<T> Debug for Vec<T> where
T: IntoVal<Env, RawVal> + TryFromVal<Env, RawVal> + Debug + Clone,
T::Error: Debug,
impl<T> Debug for Vec<T> where
T: IntoVal<Env, RawVal> + TryFromVal<Env, RawVal> + Debug + Clone,
T::Error: Debug,
sourceimpl<T> From<Vec<T>> for EnvVal<Env, Object> where
T: IntoVal<Env, RawVal> + TryFromVal<Env, RawVal>,
impl<T> From<Vec<T>> for EnvVal<Env, Object> where
T: IntoVal<Env, RawVal> + TryFromVal<Env, RawVal>,
sourceimpl<T> IntoIterator for Vec<T> where
T: IntoVal<Env, RawVal> + TryFromVal<Env, RawVal>,
impl<T> IntoIterator for Vec<T> where
T: IntoVal<Env, RawVal> + TryFromVal<Env, RawVal>,
sourceimpl<T> Ord for Vec<T> where
T: IntoVal<Env, RawVal> + TryFromVal<Env, RawVal>,
impl<T> Ord for Vec<T> where
T: IntoVal<Env, RawVal> + TryFromVal<Env, RawVal>,
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
Restrict a value to a certain interval. Read more
sourceimpl<T> PartialOrd<Vec<T>> for Vec<T> where
T: IntoVal<Env, RawVal> + TryFromVal<Env, RawVal>,
impl<T> PartialOrd<Vec<T>> for Vec<T> where
T: IntoVal<Env, RawVal> + TryFromVal<Env, RawVal>,
sourcefn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl<T> TryFrom<EnvVal<Env, Object>> for Vec<T> where
T: IntoVal<Env, RawVal> + TryFromVal<Env, RawVal>,
impl<T> TryFrom<EnvVal<Env, Object>> for Vec<T> where
T: IntoVal<Env, RawVal> + TryFromVal<Env, RawVal>,
sourceimpl<T> TryFrom<EnvVal<Env, RawVal>> for Vec<T> where
T: IntoVal<Env, RawVal> + TryFromVal<Env, RawVal>,
impl<T> TryFrom<EnvVal<Env, RawVal>> for Vec<T> where
T: IntoVal<Env, RawVal> + TryFromVal<Env, RawVal>,
sourceimpl<T> TryFrom<EnvVal<Env, ScVal>> for Vec<T> where
T: IntoVal<Env, RawVal> + TryFromVal<Env, RawVal>,
impl<T> TryFrom<EnvVal<Env, ScVal>> for Vec<T> where
T: IntoVal<Env, RawVal> + TryFromVal<Env, RawVal>,
sourceimpl<T> TryIntoVal<Env, Vec<T>> for RawVal where
T: IntoVal<Env, RawVal> + TryFromVal<Env, RawVal>,
impl<T> TryIntoVal<Env, Vec<T>> for RawVal where
T: IntoVal<Env, RawVal> + TryFromVal<Env, RawVal>,
type Error = ConversionError
fn try_into_val(self, env: &Env) -> Result<Vec<T>, Self::Error>
fn try_into_env_val(self, env: &E) -> Result<EnvVal<E, V>, Self::Error>
sourceimpl<T> TryIntoVal<Env, Vec<T>> for ScVal where
T: IntoVal<Env, RawVal> + TryFromVal<Env, RawVal>,
impl<T> TryIntoVal<Env, Vec<T>> for ScVal where
T: IntoVal<Env, RawVal> + TryFromVal<Env, RawVal>,
type Error = ConversionError
fn try_into_val(self, env: &Env) -> Result<Vec<T>, Self::Error>
fn try_into_env_val(self, env: &E) -> Result<EnvVal<E, V>, Self::Error>
impl<T> Eq for Vec<T> where
T: IntoVal<Env, RawVal> + TryFromVal<Env, RawVal>,
Auto Trait Implementations
impl<T> !RefUnwindSafe for Vec<T>
impl<T> !Send for Vec<T>
impl<T> !Sync for Vec<T>
impl<T> Unpin for Vec<T> where
T: Unpin,
impl<T> !UnwindSafe for Vec<T>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more