Skip to content

Commit 115f0e4

Browse files
authored
Merge pull request #471 from rust-osdev/fix/expose-debug-str
expose DEBUG_STR more directly
2 parents a20e690 + 0372e63 commit 115f0e4

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

src/instructions/port.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ impl PortWrite for u32 {
6868
}
6969

7070
/// A marker trait for access types which allow accessing port values.
71-
pub trait PortAccess: Sealed {}
71+
pub trait PortAccess: Sealed {
72+
/// A string representation for debug output.
73+
const DEBUG_STR: &'static str;
74+
}
7275

7376
/// A marker trait for access types which allow reading port values.
7477
pub trait PortReadAccess: PortAccess {}
@@ -80,30 +83,30 @@ pub trait PortWriteAccess: PortAccess {}
8083
#[derive(Debug)]
8184
pub struct ReadOnlyAccess(());
8285

83-
impl Sealed for ReadOnlyAccess {
86+
impl Sealed for ReadOnlyAccess {}
87+
impl PortAccess for ReadOnlyAccess {
8488
const DEBUG_STR: &'static str = "ReadOnly";
8589
}
86-
impl PortAccess for ReadOnlyAccess {}
8790
impl PortReadAccess for ReadOnlyAccess {}
8891

8992
/// An access marker type indicating that a port is only allowed to write values.
9093
#[derive(Debug)]
9194
pub struct WriteOnlyAccess(());
9295

93-
impl Sealed for WriteOnlyAccess {
96+
impl Sealed for WriteOnlyAccess {}
97+
impl PortAccess for WriteOnlyAccess {
9498
const DEBUG_STR: &'static str = "WriteOnly";
9599
}
96-
impl PortAccess for WriteOnlyAccess {}
97100
impl PortWriteAccess for WriteOnlyAccess {}
98101

99102
/// An access marker type indicating that a port is allowed to read or write values.
100103
#[derive(Debug)]
101104
pub struct ReadWriteAccess(());
102105

103-
impl Sealed for ReadWriteAccess {
106+
impl Sealed for ReadWriteAccess {}
107+
impl PortAccess for ReadWriteAccess {
104108
const DEBUG_STR: &'static str = "ReadWrite";
105109
}
106-
impl PortAccess for ReadWriteAccess {}
107110
impl PortReadAccess for ReadWriteAccess {}
108111
impl PortWriteAccess for ReadWriteAccess {}
109112

src/lib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,5 @@ impl PrivilegeLevel {
6565
}
6666

6767
pub(crate) mod sealed {
68-
pub trait Sealed {
69-
/// A string representation for debug output.
70-
const DEBUG_STR: &'static str;
71-
}
68+
pub trait Sealed {}
7269
}

src/structures/paging/page.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ use core::ops::{Add, AddAssign, Sub, SubAssign};
1414
pub trait PageSize: Copy + Eq + PartialOrd + Ord + Sealed {
1515
/// The page size in bytes.
1616
const SIZE: u64;
17+
18+
/// A string representation of the page size for debug output.
19+
const DEBUG_STR: &'static str;
1720
}
1821

1922
/// This trait is implemented for 4KiB and 2MiB pages, but not for 1GiB pages.
@@ -35,32 +38,29 @@ pub enum Size1GiB {}
3538

3639
impl PageSize for Size4KiB {
3740
const SIZE: u64 = 4096;
41+
const DEBUG_STR: &'static str = "4KiB";
3842
}
3943

4044
impl NotGiantPageSize for Size4KiB {}
4145

42-
impl Sealed for super::Size4KiB {
43-
const DEBUG_STR: &'static str = "4KiB";
44-
}
46+
impl Sealed for super::Size4KiB {}
4547

4648
impl PageSize for Size2MiB {
4749
const SIZE: u64 = Size4KiB::SIZE * 512;
50+
const DEBUG_STR: &'static str = "2MiB";
4851
}
4952

5053
impl NotGiantPageSize for Size2MiB {}
5154

52-
impl Sealed for super::Size2MiB {
53-
const DEBUG_STR: &'static str = "2MiB";
54-
}
55+
impl Sealed for super::Size2MiB {}
5556

5657
impl PageSize for Size1GiB {
5758
const SIZE: u64 = Size2MiB::SIZE * 512;
58-
}
59-
60-
impl Sealed for super::Size1GiB {
6159
const DEBUG_STR: &'static str = "1GiB";
6260
}
6361

62+
impl Sealed for super::Size1GiB {}
63+
6464
/// A virtual memory page.
6565
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
6666
#[repr(C)]

0 commit comments

Comments
 (0)