- 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.
推薦閱讀
- Spring Boot開發(fā)與測試實戰(zhàn)
- 自己動手實現(xiàn)Lua:虛擬機、編譯器和標準庫
- JMeter 性能測試實戰(zhàn)(第2版)
- Flink SQL與DataStream入門、進階與實戰(zhàn)
- MATLAB 2020 從入門到精通
- Koa開發(fā):入門、進階與實戰(zhàn)
- Python自然語言處理(微課版)
- Web全棧工程師的自我修養(yǎng)
- 劍指MySQL:架構(gòu)、調(diào)優(yōu)與運維
- Learning FuelPHP for Effective PHP Development
- Android驅(qū)動開發(fā)權(quán)威指南
- 跟戴銘學iOS編程:理順核心知識點
- 貫通Tomcat開發(fā)
- SQL Server實例教程(2008版)
- Learning Azure DocumentDB