官术网_书友最值得收藏!

Vectors

While arrays are simple to use, they have a single big disadvantage: they cannot be resized. The vector (Vec) acts in a way similar to a List in C#. It is also a generic type, as Vec itself is actually Vec<T>.

The Vec type is found in the standard library (std::vec).

To create a vector, we use something akin to either of the following:

let mut my_vector: Vec<f32> = Vec::new(); // explicit definition 

Or this:

let mut my_alt_vector = vec![4f32, 3.14, 6.28, 13.54, 27.08]; 

The f32 within the Vec macro tells the compiler that the type for the vector is f32. The f32 can be omitted, as the compiler can determine the type for the vector.

主站蜘蛛池模板: 阳原县| 阿拉尔市| 富源县| 瑞金市| 慈溪市| 湘乡市| 镇平县| 和林格尔县| 镇远县| 固始县| 西乌| 宜章县| 苏尼特左旗| 弋阳县| 黄大仙区| 尚义县| 武定县| 栖霞市| 阿尔山市| 安岳县| 兰溪市| 敦煌市| 连州市| 刚察县| 静安区| 海南省| 怀仁县| 镇江市| 廉江市| 南城县| 曲麻莱县| 浦东新区| 雷州市| 舞钢市| 云安县| 衡南县| 凤凰县| 婺源县| 宁都县| 白城市| 金门县|