Further clarification on the benefits of passing in immutable slices to functions

This commit is contained in:
mckzm
2024-06-15 13:44:11 +09:00
committed by GitHub
parent a637487fad
commit 0120c3a979

View File

@ -113,7 +113,7 @@ fn main() {
### Slicing ### Slicing
Immutable or mutable slices of Vecs can be taken, using `&` or `&mut, respectively. Immutable or mutable slices of Vecs can be taken, using `&` or `&mut, respectively.
In Rust, its more common to pass immutable slices as arguments rather than vectors when you just want to provide read access. The same goes for `String` and `&str`. In Rust, its more common to pass immutable slices as arguments rather than vectors when you just want to provide read access, as this is more flexible (no move) and efficient (no copy). The same goes for `String` and `&str`.
5. 🌟🌟 5. 🌟🌟
```rust,editable ```rust,editable