mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 22:37:49 +00:00
Link if let and shadowing chapters under keyboard code
This commit is contained in:
@@ -576,7 +576,13 @@ extern "x86-interrupt" fn keyboard_interrupt_handler(
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
The above code just translates keypresses of the number keys 0-9 and ignores all other keys. Now we can write numbers:
|
The above code translates keypresses of the number keys 0-9 and ignores all other keys. It uses a [match] statement to assign a character or `None` to each scancode. It then uses [`if let`] to destructure the optional `key`. By using the same variable name `key` in the pattern, we [shadow] the previous declaration, which is a common pattern for destructuring `Option` types in Rust.
|
||||||
|
|
||||||
|
[match]: https://doc.rust-lang.org/book/ch06-02-match.html
|
||||||
|
[`if let`]: https://doc.rust-lang.org/book/ch18-01-all-the-places-for-patterns.html#conditional-if-let-expressions
|
||||||
|
[shadow]: https://doc.rust-lang.org/book/ch03-01-variables-and-mutability.html#shadowing
|
||||||
|
|
||||||
|
Now we can write numbers:
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user