Struct PageRange

Source
pub struct PageRange { /* private fields */ }
Expand description

A non-empty page-aligned memory range.

Implementations§

Source§

impl PageRange

Source

pub const fn new(start: usize, end: 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:

  • start must be smaller than end,

  • start and end must be aligned to PAGE_SIZE.

§Examples
use free_list::PageRange;

let range = PageRange::new(0x1000, 0x5000).unwrap();
Source

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 and len must be aligned to PAGE_SIZE,

  • start + len must not overflow.

§Examples
use free_list::PageRange;

let range = PageRange::from_start_len(0x1000, 0x4000).unwrap();
Source

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);
Source

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);
Source

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);
Source

pub const fn pages(self) -> NonZeroUsize

Returns the length of this page range in pages of size PAGE_SIZE.

§Examples
use free_list::PageRange;

let range = PageRange::new(0x1000, 0x5000).unwrap();
assert_eq!(range.pages().get(), 4);
Source

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));
Source

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));
Source

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));
Source

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 Add for PageRange

Source§

type Output = Option<PageRange>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl Clone for PageRange

Source§

fn clone(&self) -> PageRange

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PageRange

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for PageRange

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<S: PageSize> From<PhysFrame<S>> for PageRange

Source§

fn from(value: PhysFrame<S>) -> Self

Converts to this type from the input type.
Source§

impl Hash for PageRange

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for PageRange

Source§

fn eq(&self, other: &PageRange) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for PageRange

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Sub for PageRange

Source§

type Output = PageRangeSub

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl TryFrom<Range<usize>> for PageRange

Source§

type Error = PageRangeError

The type returned in the event of a conversion error.
Source§

fn try_from(value: Range<usize>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Copy for PageRange

Source§

impl Eq for PageRange

Source§

impl StructuralPartialEq for PageRange

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.