100 exercises to learn Rust

This commit is contained in:
LukeMathWalker
2024-05-12 22:21:03 +02:00
commit 5edebf6cf2
309 changed files with 13173 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
# Mutable indexing
`Index` allows read-only access. It doesn't let you mutate the value you
retrieved.
## `IndexMut`
If you want to allow mutability, you need to implement the `IndexMut` trait.
```rust
// Slightly simplified
pub trait IndexMut<Idx>: Index<Idx>
{
// Required method
fn index_mut(&mut self, index: Idx) -> &mut Self::Output;
}
```
`IndexMut` can only be implemented if the type already implements `Index`,
since it unlocks an _additional_ capability.