pub struct PageRange { /* private fields */ }
Expand description
A non-empty page-aligned memory range.
Implementations§
Source§impl PageRange
impl PageRange
Sourcepub const fn from_start_len(
start: usize,
len: usize,
) -> Result<Self, PageRangeError>
pub const fn from_start_len( start: usize, len: usize, ) -> Result<Self, PageRangeError>
Constructs a new PageRange
from a given start
and end
,
or returns PageRangeError
if any of the following conidtions
are not met:
-
len
must not be zero, -
start
andlen
must be aligned toPAGE_SIZE
, -
start + len
must not overflow.
§Examples
use free_list::PageRange;
let range = PageRange::from_start_len(0x1000, 0x4000).unwrap();
Sourcepub const fn start(self) -> usize
pub const fn start(self) -> usize
Returns the start address of this page range.
§Examples
use free_list::PageRange;
let range = PageRange::new(0x1000, 0x5000).unwrap();
assert_eq!(range.start(), 0x1000);
Sourcepub const fn end(self) -> usize
pub const fn end(self) -> usize
Returns the end address of this page range.
§Examples
use free_list::PageRange;
let range = PageRange::new(0x1000, 0x5000).unwrap();
assert_eq!(range.end(), 0x5000);
Sourcepub const fn len(self) -> NonZeroUsize
pub const fn len(self) -> NonZeroUsize
Returns the length of this page range in bytes.
§Examples
use free_list::PageRange;
let range = PageRange::new(0x1000, 0x5000).unwrap();
assert_eq!(range.len().get(), 0x4000);
Sourcepub const fn pages(self) -> NonZeroUsize
pub const fn pages(self) -> NonZeroUsize
Sourcepub const fn overlaps(self, other: Self) -> bool
pub const fn overlaps(self, other: Self) -> bool
Returns true if self
overlaps with other
.
This property is exclusive with PageRange::touches
.
§Examples
use free_list::PageRange;
let a = PageRange::new(0x1000, 0x5000).unwrap();
let b = PageRange::new(0x3000, 0x7000).unwrap();
assert!(a.overlaps(b));
Sourcepub const fn touches(self, other: Self) -> bool
pub const fn touches(self, other: Self) -> bool
Returns true if self
touches other
.
This is exclusive with PageRange::overlaps
.
§Examples
use free_list::PageRange;
let a = PageRange::new(0x1000, 0x5000).unwrap();
let b = PageRange::new(0x5000, 0x9000).unwrap();
assert!(a.touches(b));
Sourcepub const fn contains(self, other: Self) -> bool
pub const fn contains(self, other: Self) -> bool
Returns true if self
contains other
.
§Examples
use free_list::PageRange;
let a = PageRange::new(0x1000, 0x5000).unwrap();
let b = PageRange::new(0x1000, 0x3000).unwrap();
assert!(a.contains(b));
Sourcepub const fn fit(self, layout: PageLayout) -> Option<PageRange>
pub const fn fit(self, layout: PageLayout) -> Option<PageRange>
Returns the first page range that is contained in self
and satisfies layout
.
§Examples
use free_list::{PageLayout, PageRange};
let range = PageRange::new(0x1000, 0x5000).unwrap();
let layout = PageLayout::from_size_align(0x3000, 0x2000).unwrap();
let expected = PageRange::new(0x2000, 0x5000).unwrap();
assert_eq!(range.fit(layout), Some(expected));
Trait Implementations§
Source§impl PartialOrd for PageRange
impl PartialOrd for PageRange
impl Copy for PageRange
impl Eq for PageRange
impl StructuralPartialEq for PageRange
Auto Trait Implementations§
impl Freeze for PageRange
impl RefUnwindSafe for PageRange
impl Send for PageRange
impl Sync for PageRange
impl Unpin for PageRange
impl UnwindSafe for PageRange
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more