数组向量

数组向量 (array vector) 是一种特殊的向量,用于存储可变长度的二维数组。

本节将介绍数组向量的创建及其数据的写入。

创建数组向量

结构体 ArrayVector<S> 提供了 new 方法,用于创建数组向量,签名如下:

pub fn new() -> Self

几个常用的类型别名定义如下:

pub type CharArrayVector = ArrayVector<i8>;
pub type ShortArrayVector = ArrayVector<i16>;
pub type IntArrayVector = ArrayVector<i32>;
pub type LongArrayVector = ArrayVector<i64>;
pub type FloatArrayVector = ArrayVector<f32>;
pub type DoubleArrayVector = ArrayVector<f64>;

写入数据

通过 push 方法,将数据追加到数组向量末尾,签名如下:

pub fn push(&mut self, value: Vec<S>)

示例如下

let mut prices = DoubleArrayVector::new();
let price1 = vec![1.1, 2.2, 3.3];
prices.push(price1);
let price2 = vec![4.4, 5.5];
prices.push(price2);