- 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.
推薦閱讀
- C++程序設計教程
- Android應用程序開發與典型案例
- Java EE 6 企業級應用開發教程
- Android Development with Kotlin
- 我的第一本算法書
- Android Application Development Cookbook(Second Edition)
- oreilly精品圖書:軟件開發者路線圖叢書(共8冊)
- NativeScript for Angular Mobile Development
- 零基礎學Java(第4版)
- Java性能權威指南(第2版)
- MATLAB for Machine Learning
- C語言程序設計
- 深入淺出Go語言編程
- Spring技術內幕:深入解析Spring架構與設計原理(第2版)
- 寫給大家看的Midjourney設計書