Struct memory_structs::FrameRange
source · pub struct FrameRange<P: PageSize = Page4K>(/* private fields */);
Expand description
A range of Frame
s that are contiguous in physical memory.
Implementations§
source§impl FrameRange<Page4K>
impl FrameRange<Page4K>
sourcepub const fn from_phys_addr(
starting_addr: PhysicalAddress,
size_in_bytes: usize
) -> FrameRange
pub const fn from_phys_addr( starting_addr: PhysicalAddress, size_in_bytes: usize ) -> FrameRange
A convenience method for creating a new FrameRange
that spans all Frame
s from the given PhysicalAddress
to an end bound based on the given size.
source§impl<P: PageSize> FrameRange<P>
impl<P: PageSize> FrameRange<P>
sourcepub const fn empty() -> Self
pub const fn empty() -> Self
Creates an empty FrameRange
that will always yield None
when iterated.
sourcepub const fn new(start: Frame<P>, end: Frame<P>) -> FrameRange<P>
pub const fn new(start: Frame<P>, end: Frame<P>) -> FrameRange<P>
Creates a new range of Frame
s that spans from start
to end
, both inclusive bounds.
sourcepub const fn start_address(&self) -> PhysicalAddress
pub const fn start_address(&self) -> PhysicalAddress
Returns the PhysicalAddress
of the starting Frame
in this FrameRange
.
sourcepub const fn size_in_frames(&self) -> usize
pub const fn size_in_frames(&self) -> usize
Returns the number of Frame
s 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: PhysicalAddress) -> bool
pub const fn contains_address(&self, addr: PhysicalAddress) -> bool
Returns true
if this FrameRange
contains the given PhysicalAddress
.
sourcepub const fn offset_of_address(&self, addr: PhysicalAddress) -> Option<usize>
pub const fn offset_of_address(&self, addr: PhysicalAddress) -> Option<usize>
Returns the offset of the given PhysicalAddress
within this FrameRange
, i.e., addr - self.start_address()
.
If the given addr
is not covered by this range of Frame
s, 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<PhysicalAddress>
pub const fn address_at_offset(&self, offset: usize) -> Option<PhysicalAddress>
Returns the PhysicalAddress
at the given offset
into this FrameRange
within this FrameRange
, i.e., self.start_address() + offset
.
If the given offset
is not within this range of Frame
s, 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: Frame<P>) -> FrameRange<P>
pub fn to_extended(&self, to_include: Frame<P>) -> FrameRange<P>
Returns a new separate FrameRange
that is extended to include the given Frame
.
sourcepub fn contains_range(&self, other: &FrameRange<P>) -> bool
pub fn contains_range(&self, other: &FrameRange<P>) -> bool
Returns true
if the other
FrameRange
is fully contained within this FrameRange
.
sourcepub fn overlap(&self, other: &FrameRange<P>) -> Option<FrameRange<P>>
pub fn overlap(&self, other: &FrameRange<P>) -> Option<FrameRange<P>>
Returns an inclusive FrameRange
representing the Frame
s that overlap across this FrameRange
and the given other FrameRange
.
If there is no overlap between the two ranges, None
is returned.
sourcepub fn into_4k_frames(self) -> FrameRange<Page4K>
pub fn into_4k_frames(self) -> FrameRange<Page4K>
Converts this range of Frame
s into an identical 4K-sized range.
Methods from Deref<Target = RangeInclusive<Frame<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.
Trait Implementations§
source§impl<P: Clone + PageSize> Clone for FrameRange<P>
impl<P: Clone + PageSize> Clone for FrameRange<P>
source§fn clone(&self) -> FrameRange<P>
fn clone(&self) -> FrameRange<P>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<P: PageSize> Debug for FrameRange<P>
impl<P: PageSize> Debug for FrameRange<P>
source§impl<P: PageSize> Default for FrameRange<P>
impl<P: PageSize> Default for FrameRange<P>
source§impl<P: PageSize> Deref for FrameRange<P>
impl<P: PageSize> Deref for FrameRange<P>
§type Target = RangeInclusive<Frame<P>>
type Target = RangeInclusive<Frame<P>>
source§fn deref(&self) -> &RangeInclusive<Frame<P>>
fn deref(&self) -> &RangeInclusive<Frame<P>>
source§impl DerefMut for FrameRange
impl DerefMut for FrameRange
source§fn deref_mut(&mut self) -> &mut RangeInclusive<Frame>
fn deref_mut(&mut self) -> &mut RangeInclusive<Frame>
source§impl From<FrameRange<Page1G>> for FrameRange<Page4K>
impl From<FrameRange<Page1G>> for FrameRange<Page4K>
source§fn from(r: FrameRange<Page1G>) -> Self
fn from(r: FrameRange<Page1G>) -> Self
source§impl From<FrameRange<Page2M>> for FrameRange<Page4K>
impl From<FrameRange<Page2M>> for FrameRange<Page4K>
source§fn from(r: FrameRange<Page2M>) -> Self
fn from(r: FrameRange<Page2M>) -> Self
source§impl<P: PageSize> IntoIterator for &FrameRange<P>
impl<P: PageSize> IntoIterator for &FrameRange<P>
source§impl<P: PageSize> IntoIterator for FrameRange<P>
impl<P: PageSize> IntoIterator for FrameRange<P>
source§impl<P: PartialEq + PageSize> PartialEq<FrameRange<P>> for FrameRange<P>
impl<P: PartialEq + PageSize> PartialEq<FrameRange<P>> for FrameRange<P>
source§fn eq(&self, other: &FrameRange<P>) -> bool
fn eq(&self, other: &FrameRange<P>) -> bool
self
and other
values to be equal, and is used
by ==
.