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>
impl PageRange<Page4K>
pub const fn from_virt_addr(
starting_addr: VirtualAddress,
size_in_bytes: usize
) -> 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,
impl<P> PageRange<P>where P: PageSize,
pub const fn empty() -> PageRange<P>
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>
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_address(&self) -> VirtualAddress
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
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
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
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>
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>
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>
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
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>>
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>
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.