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

  • Learning Rust
  • Paul Johnson Vesa Kaihlavirta
  • 107字
  • 2021-07-02 23:07:19

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.

主站蜘蛛池模板: 高雄市| 蒙自县| 武隆县| 惠来县| 延吉市| 扎兰屯市| 麟游县| 城市| 阿拉善左旗| 尼玛县| 拜城县| 东乡| 阆中市| 盐山县| 陈巴尔虎旗| 封开县| 大港区| 区。| 克拉玛依市| 墨脱县| 彰化县| 石阡县| 玛纳斯县| 兴安盟| 晋宁县| 定西市| 西充县| 屯门区| 古蔺县| 土默特右旗| 永寿县| 武义县| 巴林左旗| 嵩明县| 建昌县| 香格里拉县| 海门市| 达孜县| 凤城市| 南充市| 库尔勒市|