Skip to content

Commit 129fa95

Browse files
authored
Merge pull request #315 from Freax13/add-derives
Derive common traits for number, range and enum types
2 parents f4c2e26 + 640d425 commit 129fa95

File tree

7 files changed

+14
-14
lines changed

7 files changed

+14
-14
lines changed

src/addr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use bit_field::BitField;
1717
/// On `x86_64`, only the 48 lower bits of a virtual address can be used. The top 16 bits need
1818
/// to be copies of bit 47, i.e. the most significant bit. Addresses that fulfil this criterium
1919
/// are called “canonical”. This type guarantees that it always represents a canonical address.
20-
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
20+
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
2121
#[repr(transparent)]
2222
pub struct VirtAddr(u64);
2323

@@ -30,7 +30,7 @@ pub struct VirtAddr(u64);
3030
///
3131
/// On `x86_64`, only the 52 lower bits of a physical address can be used. The top 12 bits need
3232
/// to be zero. This type guarantees that it always represents a valid physical address.
33-
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
33+
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
3434
#[repr(transparent)]
3535
pub struct PhysAddr(u64);
3636

src/instructions/tlb.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ struct InvpcidDescriptor {
4949

5050
/// Structure of a PCID. A PCID has to be <= 4096 for x86_64.
5151
#[repr(transparent)]
52-
#[derive(Debug)]
52+
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
5353
pub struct Pcid(u16);
5454

5555
impl Pcid {

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub mod registers;
6767
pub mod structures;
6868

6969
/// Represents a protection ring level.
70-
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
70+
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
7171
#[repr(u8)]
7272
pub enum PrivilegeLevel {
7373
/// Privilege-level 0 (most privilege): This level is used by critical system-software

src/registers/segmentation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub trait Segment64: Segment {
6262
/// with some additional flags).
6363
///
6464
/// See Intel 3a, Section 3.4.2 "Segment Selectors"
65-
#[derive(Clone, Copy, PartialEq, Eq)]
65+
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
6666
#[repr(transparent)]
6767
pub struct SegmentSelector(pub u16);
6868

src/structures/paging/frame.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use core::marker::PhantomData;
88
use core::ops::{Add, AddAssign, Sub, SubAssign};
99

1010
/// A physical memory frame.
11-
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
11+
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
1212
#[repr(C)]
1313
pub struct PhysFrame<S: PageSize = Size4KiB> {
1414
pub(crate) start_address: PhysAddr, // TODO: remove when start_address() is const
@@ -135,7 +135,7 @@ impl<S: PageSize> Sub<PhysFrame<S>> for PhysFrame<S> {
135135
}
136136

137137
/// An range of physical memory frames, exclusive the upper bound.
138-
#[derive(Clone, Copy, PartialEq, Eq)]
138+
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
139139
#[repr(C)]
140140
pub struct PhysFrameRange<S: PageSize = Size4KiB> {
141141
/// The start of the range, inclusive.
@@ -177,7 +177,7 @@ impl<S: PageSize> fmt::Debug for PhysFrameRange<S> {
177177
}
178178

179179
/// An range of physical memory frames, inclusive the upper bound.
180-
#[derive(Clone, Copy, PartialEq, Eq)]
180+
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
181181
#[repr(C)]
182182
pub struct PhysFrameRangeInclusive<S: PageSize = Size4KiB> {
183183
/// The start of the range, inclusive.

src/structures/paging/page.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl PageSize for Size1GiB {
5353
}
5454

5555
/// A virtual memory page.
56-
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
56+
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
5757
#[repr(C)]
5858
pub struct Page<S: PageSize = Size4KiB> {
5959
start_address: VirtAddr,
@@ -275,7 +275,7 @@ impl<S: PageSize> Sub<Self> for Page<S> {
275275
}
276276

277277
/// A range of pages with exclusive upper bound.
278-
#[derive(Clone, Copy, PartialEq, Eq)]
278+
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
279279
#[repr(C)]
280280
pub struct PageRange<S: PageSize = Size4KiB> {
281281
/// The start of the range, inclusive.
@@ -328,7 +328,7 @@ impl<S: PageSize> fmt::Debug for PageRange<S> {
328328
}
329329

330330
/// A range of pages with inclusive upper bound.
331-
#[derive(Clone, Copy, PartialEq, Eq)]
331+
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
332332
#[repr(C)]
333333
pub struct PageRangeInclusive<S: PageSize = Size4KiB> {
334334
/// The start of the range, inclusive.

src/structures/paging/page_table.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ impl fmt::Debug for PageTable {
268268
/// Can be used to select one of the 512 entries of a page table.
269269
///
270270
/// Guaranteed to only ever contain 0..512.
271-
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
271+
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
272272
pub struct PageTableIndex(u16);
273273

274274
impl PageTableIndex {
@@ -319,7 +319,7 @@ impl From<PageTableIndex> for usize {
319319
/// This type is returned by the `VirtAddr::page_offset` method.
320320
///
321321
/// Guaranteed to only ever contain 0..4096.
322-
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
322+
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
323323
pub struct PageOffset(u16);
324324

325325
impl PageOffset {
@@ -365,7 +365,7 @@ impl From<PageOffset> for usize {
365365
}
366366
}
367367

368-
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
368+
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
369369
/// A value between 1 and 4.
370370
pub enum PageTableLevel {
371371
/// Represents the level for a page table.

0 commit comments

Comments
 (0)