mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 14:27:49 +00:00
Update blog to 23df363136
This commit is contained in:
@@ -345,21 +345,21 @@ To model the levels we use a trait and empty enums:
|
||||
pub trait TableLevel {}
|
||||
|
||||
pub enum Level4 {}
|
||||
enum Level3 {}
|
||||
enum Level2 {}
|
||||
enum Level1 {}
|
||||
pub enum Level3 {}
|
||||
pub enum Level2 {}
|
||||
pub enum Level1 {}
|
||||
|
||||
impl TableLevel for Level4 {}
|
||||
impl TableLevel for Level3 {}
|
||||
impl TableLevel for Level2 {}
|
||||
impl TableLevel for Level1 {}
|
||||
```
|
||||
An empty enum has size zero and disappears completely after compiling. Unlike an empty struct, it's not possible to instantiate an empty enum. Since we will use `TableLevel` and `Level4` in exported types, they need to be public as well.
|
||||
An empty enum has size zero and disappears completely after compiling. Unlike an empty struct, it's not possible to instantiate an empty enum. Since we will use `TableLevel` and the table levels in exported types, they need to be public.
|
||||
|
||||
To differentiate the P1 table from the other tables, we introduce a `HierarchicalLevel` trait, which is a subtrait of `TableLevel`. But we implement it only for the levels 4, 3, and 2:
|
||||
|
||||
```rust
|
||||
trait HierarchicalLevel: TableLevel {}
|
||||
pub trait HierarchicalLevel: TableLevel {}
|
||||
|
||||
impl HierarchicalLevel for Level4 {}
|
||||
impl HierarchicalLevel for Level3 {}
|
||||
|
||||
Reference in New Issue
Block a user