Struct memory_structs::PageRange
source · pub struct PageRange<P: PageSize = Page4K>(/* private fields */);Expand description
A range of Pages that are contiguous in virtual memory.
Implementations§
source§impl PageRange<Page4K>
impl PageRange<Page4K>
sourcepub const fn from_virt_addr(
starting_addr: VirtualAddress,
size_in_bytes: usize
) -> PageRange
pub const fn from_virt_addr( starting_addr: VirtualAddress, size_in_bytes: usize ) -> PageRange
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.
source§impl<P: PageSize> PageRange<P>
impl<P: PageSize> PageRange<P>
sourcepub const fn empty() -> Self
pub const fn empty() -> Self
Creates an empty PageRange that will always yield None when iterated.
sourcepub const fn new(start: Page<P>, end: Page<P>) -> PageRange<P>
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.
sourcepub const fn start_address(&self) -> VirtualAddress
pub const fn start_address(&self) -> VirtualAddress
Returns the VirtualAddress of the starting Page in this PageRange.
sourcepub const fn size_in_pages(&self) -> usize
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.
sourcepub const fn size_in_bytes(&self) -> usize
pub const fn size_in_bytes(&self) -> usize
Returns the size of this range in bytes.
sourcepub const fn contains_address(&self, addr: VirtualAddress) -> bool
pub const fn contains_address(&self, addr: VirtualAddress) -> bool
Returns true if this PageRange contains the given VirtualAddress.
sourcepub const fn offset_of_address(&self, addr: VirtualAddress) -> Option<usize>
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).
sourcepub const fn address_at_offset(&self, offset: usize) -> Option<VirtualAddress>
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.
sourcepub fn to_extended(&self, to_include: Page<P>) -> PageRange<P>
pub fn to_extended(&self, to_include: Page<P>) -> PageRange<P>
Returns a new separate PageRange that is extended to include the given Page.
sourcepub fn contains_range(&self, other: &PageRange<P>) -> bool
pub fn contains_range(&self, other: &PageRange<P>) -> bool
Returns true if the other PageRange is fully contained within this PageRange.
sourcepub fn overlap(&self, other: &PageRange<P>) -> Option<PageRange<P>>
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.
sourcepub fn into_4k_pages(self) -> PageRange<Page4K>
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>>>§
sourcepub fn iter(&self) -> RangeInclusiveIterator<Idx>
pub fn iter(&self) -> RangeInclusiveIterator<Idx>
Returns an iterator with the same start and end values as the range.
sourcepub fn contains<U>(&self, item: &U) -> boolwhere
Idx: PartialOrd<U>,
U: PartialOrd<Idx> + ?Sized,
pub fn contains<U>(&self, item: &U) -> boolwhere Idx: PartialOrd<U>, U: PartialOrd<Idx> + ?Sized,
Returns true if item is contained in the range.