Skip to content

Commit

Permalink
Merge pull request #490 from Wasabi375/zst_hash
Browse files Browse the repository at this point in the history
Ensure that Page actually implements Hash
  • Loading branch information
Freax13 authored Jul 4, 2024
2 parents 24691eb + b0843da commit 2d3bd56
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/structures/paging/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ pub trait PageSize: Copy + Eq + PartialOrd + Ord + Sealed {
pub trait NotGiantPageSize: PageSize {}

/// A standard 4KiB page.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum Size4KiB {}

/// A “huge” 2MiB page.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum Size2MiB {}

/// A “giant” 1GiB page.
///
/// (Only available on newer x86_64 CPUs.)
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum Size1GiB {}

impl PageSize for Size4KiB {
Expand Down Expand Up @@ -429,6 +429,15 @@ impl fmt::Display for AddressNotAligned {
mod tests {
use super::*;

fn test_is_hash<T: core::hash::Hash>() {}

#[test]
pub fn test_page_is_hash() {
test_is_hash::<Page<Size4KiB>>();
test_is_hash::<Page<Size2MiB>>();
test_is_hash::<Page<Size1GiB>>();
}

#[test]
pub fn test_page_ranges() {
let page_size = Size4KiB::SIZE;
Expand Down

0 comments on commit 2d3bd56

Please sign in to comment.