- 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.
推薦閱讀
- Learning LibGDX Game Development(Second Edition)
- Beginning C++ Game Programming
- AIRAndroid應用開發實戰
- Web全棧工程師的自我修養
- Learning Apache Kafka(Second Edition)
- 正則表達式經典實例(第2版)
- C語言程序設計
- SAP BusinessObjects Dashboards 4.1 Cookbook
- 零基礎學單片機C語言程序設計
- Python時間序列預測
- Flutter跨平臺開發入門與實戰
- Python+Tableau數據可視化之美
- MySQL入門很輕松(微課超值版)
- Spring 5 Design Patterns
- Instant Apache Camel Messaging System