mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 22:37:49 +00:00
Update blog to 75aa669cdb
This commit is contained in:
@@ -58,6 +58,7 @@ All of the code below goes into our new module (unless specified otherwise).
|
|||||||
First, we represent the different colors using an enum:
|
First, we represent the different colors using an enum:
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
|
#[allow(dead_code)]
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
pub enum Color {
|
pub enum Color {
|
||||||
Black = 0,
|
Black = 0,
|
||||||
@@ -82,6 +83,8 @@ We use a [C-like enum] here to explicitly specify the number for each color. Bec
|
|||||||
|
|
||||||
[C-like enum]: http://rustbyexample.com/custom_types/enum/c_like.html
|
[C-like enum]: http://rustbyexample.com/custom_types/enum/c_like.html
|
||||||
|
|
||||||
|
Normally the compiler would issue a warning for each unused variant. By using the `#[allow(dead_code)]` attribute we disable these warnings for the `Color` enum.
|
||||||
|
|
||||||
To represent a full color code that specifies foreground and background color, we create a [newtype] on top of `u8`:
|
To represent a full color code that specifies foreground and background color, we create a [newtype] on top of `u8`:
|
||||||
|
|
||||||
[newtype]: https://aturon.github.io/features/types/newtype.html
|
[newtype]: https://aturon.github.io/features/types/newtype.html
|
||||||
|
|||||||
Reference in New Issue
Block a user