Struct memory::PageRange

pub struct PageRange<P = Page4K>(/* private fields */)
where
    P: PageSize;
Expand description

A range of Pages that are contiguous in virtual memory.

Implementations§

§

impl PageRange<Page4K>

pub const fn from_virt_addr( starting_addr: VirtualAddress, size_in_bytes: usize ) -> PageRange<Page4K>

A convenience method for creating a new PageRange that spans all Pages from the given VirtualAddress to an end bound based on the given size.

§

impl<P> PageRange<P>where P: PageSize,

pub const fn empty() -> PageRange<P>

Creates an empty PageRange that will always yield None when iterated.

pub const fn new(start: Page<P>, end: Page<P>) -> PageRange<P>

Creates a new range of Pages that spans from start to end, both inclusive bounds.

pub const fn start(&self) -> &Page<P>

Returns the starting Page in this PageRange.

pub const fn end(&self) -> &Page<P>

Returns the ending Page in this PageRange.

pub const fn start_address(&self) -> VirtualAddress

Returns the VirtualAddress of the starting Page in this PageRange.

pub const fn size_in_pages(&self) -> usize

Returns the number of Pages covered by this iterator.

Use this instead of Iterator::count() method. This is instant, because it doesn’t need to iterate over each entry, unlike normal iterators.

pub const fn size_in_bytes(&self) -> usize

Returns the size of this range in bytes.

pub const fn contains_address(&self, addr: VirtualAddress) -> bool

Returns true if this PageRange contains the given VirtualAddress.

pub const fn offset_of_address(&self, addr: VirtualAddress) -> Option<usize>

Returns the offset of the given VirtualAddress within this PageRange, i.e., addr - self.start_address().

If the given addr is not covered by this range of Pages, this returns None.

Examples

If the range covers addresses 0x2000 to 0x4000, then offset_of_address(0x3500) would return Some(0x1500).

pub const fn address_at_offset(&self, offset: usize) -> Option<VirtualAddress>

Returns the VirtualAddress at the given offset into this PageRangewithin this PageRange, i.e., self.start_address() + offset.

If the given offset is not within this range of Pages, this returns None.

Examples

If the range covers addresses 0x2000 through 0x3FFF, then address_at_offset(0x1500) would return Some(0x3500), and address_at_offset(0x2000) would return None.

pub fn to_extended(&self, to_include: Page<P>) -> PageRange<P>

Returns a new separate PageRange that is extended to include the given Page.

pub fn contains_range(&self, other: &PageRange<P>) -> bool

Returns true if the other PageRange is fully contained within this PageRange.

pub fn overlap(&self, other: &PageRange<P>) -> Option<PageRange<P>>

Returns an inclusive PageRange representing the Pages that overlap across this PageRange and the given other PageRange.

If there is no overlap between the two ranges, None is returned.

pub fn into_4k_pages(self) -> PageRange<Page4K>

Converts this range of Pages into an identical 4K-sized range.

Methods from Deref<Target = RangeInclusive<Page<P>>>§

source

pub fn start(&self) -> &Idx

Returns the lower bound of the range (inclusive).

source

pub fn end(&self) -> &Idx

Returns the upper bound of the range (inclusive).

source

pub fn is_empty(&self) -> bool

Returns true if the range contains no items.

source

pub fn iter(&self) -> RangeInclusiveIterator<Idx>

Returns an iterator with the same start and end values as the range.

source

pub fn contains<U>(&self, item: &U) -> boolwhere Idx: PartialOrd<U>, U: PartialOrd<Idx> + ?Sized,

Returns true if item is contained in the range.

Trait Implementations§

§

impl<P> Clone for PageRange<P>where P: Clone + PageSize,

§

fn clone(&self) -> PageRange<P>

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
§

impl<P> Debug for PageRange<P>where P: PageSize,

§

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

Formats the value using the given formatter. Read more
§

impl<P> Default for PageRange<P>where P: PageSize,

§

fn default() -> PageRange<P>

Returns the “default value” for a type. Read more
§

impl<P> Deref for PageRange<P>where P: PageSize,

§

type Target = RangeInclusive<Page<P>>

The resulting type after dereferencing.
§

fn deref(&self) -> &RangeInclusive<Page<P>>

Dereferences the value.
§

impl DerefMut for PageRange<Page4K>

§

fn deref_mut(&mut self) -> &mut RangeInclusive<Page<Page4K>>

Mutably dereferences the value.
§

impl From<PageRange<Page1G>> for PageRange<Page4K>

§

fn from(r: PageRange<Page1G>) -> PageRange<Page4K>

Converts to this type from the input type.
§

impl From<PageRange<Page2M>> for PageRange<Page4K>

§

fn from(r: PageRange<Page2M>) -> PageRange<Page4K>

Converts to this type from the input type.
§

impl<P> IntoIterator for &PageRange<P>where P: PageSize,

§

type Item = Page<P>

The type of the elements being iterated over.
§

type IntoIter = RangeInclusiveIterator<Page<P>>

Which kind of iterator are we turning this into?
§

fn into_iter(self) -> <&PageRange<P> as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
§

impl<P> IntoIterator for PageRange<P>where P: PageSize,

§

type Item = Page<P>

The type of the elements being iterated over.
§

type IntoIter = RangeInclusiveIterator<Page<P>>

Which kind of iterator are we turning this into?
§

fn into_iter(self) -> <PageRange<P> as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
§

impl<P> PartialEq<PageRange<P>> for PageRange<P>where P: PartialEq<P> + PageSize,

§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

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

impl TryFrom<PageRange<Page4K>> for PageRange<Page1G>

§

type Error = &'static str

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

fn try_from(p: PageRange<Page4K>) -> Result<PageRange<Page1G>, &'static str>

Performs the conversion.
§

impl TryFrom<PageRange<Page4K>> for PageRange<Page2M>

§

type Error = &'static str

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

fn try_from(p: PageRange<Page4K>) -> Result<PageRange<Page2M>, &'static str>

Performs the conversion.
§

impl<P> Eq for PageRange<P>where P: Eq + PageSize,

§

impl<P> StructuralEq for PageRange<P>where P: PageSize,

§

impl<P> StructuralPartialEq for PageRange<P>where P: PageSize,

Auto Trait Implementations§

§

impl<P> RefUnwindSafe for PageRange<P>where P: RefUnwindSafe,

§

impl<P> Send for PageRange<P>where P: Send,

§

impl<P> Sync for PageRange<P>where P: Sync,

§

impl<P> Unpin for PageRange<P>where P: Unpin,

§

impl<P> UnwindSafe for PageRange<P>where P: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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 Twhere T: Clone,

§

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, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.