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

Manipulating an array or vector via slices

Both arrays and vectors can be accessed using a value (such as my_vec[4]). However, if you want to manipulate a section of the array, then you would take a slice from the array. A slice is like a window to a part of the original thing.

To create a slice, use this:

let my_slice = &my_vec[1..5];  

A slice also has no predefined size: it can be 2 bytes, or it can be 202 bytes. Due to this, the size of the slice is not known at compile time. This is important to know, because it prevents certain methods from working.

主站蜘蛛池模板: 镇赉县| 古田县| 汝州市| 安徽省| 拜泉县| 吉安市| 峨眉山市| 柞水县| 奉节县| 南投县| 阳新县| 呼玛县| 开鲁县| 宽甸| 稻城县| 泗水县| 上虞市| 肃北| 晴隆县| 汕尾市| 宁晋县| 和田县| 苏尼特右旗| 三江| 永新县| 铜梁县| 昆山市| 岑巩县| 杭锦后旗| 靖西县| 吉木乃县| 二连浩特市| 潼南县| 白沙| 滦平县| 新乡市| 蓬莱市| 民勤县| 新巴尔虎右旗| 故城县| 大石桥市|