Struct resources::address_range::AddressRange
source · Expand description
Represents a range of addresses from start
to end
, inclusive.
Why not use the standard RangeInclusive
? RangeInclusive
is not Copy
, because it tries to
be an iterator as well as a range (which also means it is larger than necessary). Additionally,
we would also like to implement some convenience functions for our own type.
Fields§
§start: u64
§end: u64
Implementations§
source§impl AddressRange
impl AddressRange
sourcepub const fn from_start_and_end(start: u64, end: u64) -> Self
pub const fn from_start_and_end(start: u64, end: u64) -> Self
Creates a new AddressRange
from start
and end
(inclusive) addresses.
sourcepub const fn from_start_and_size(start: u64, size: u64) -> Option<Self>
pub const fn from_start_and_size(start: u64, size: u64) -> Option<Self>
Creates a new AddressRange
from start
extending size
bytes.
Returns None
if the generated range is not representable as an AddressRange
.
sourcepub fn contains_range(&self, other: AddressRange) -> bool
pub fn contains_range(&self, other: AddressRange) -> bool
Returns true
if other
is fully contained within this range.
Empty ranges are considered to be not contained by any range.
sourcepub fn overlaps(&self, other: AddressRange) -> bool
pub fn overlaps(&self, other: AddressRange) -> bool
Returns true
if the two ranges have any addresses in common.
sourcepub fn intersect(&self, other: AddressRange) -> AddressRange
pub fn intersect(&self, other: AddressRange) -> AddressRange
Find the intersection (overlapping region) of two ranges.
If there is no intersection, the resulting AddressRange
will be empty.
sourcepub fn non_overlapping_ranges(
&self,
other: AddressRange
) -> (AddressRange, AddressRange)
pub fn non_overlapping_ranges(
&self,
other: AddressRange
) -> (AddressRange, AddressRange)
Returns the ranges of addresses contained in self
but not in other
.
The first returned range will contain the addresses in self
that are less than the start
of other
, which will be empty if the starts of the ranges coincide.
The second returned range will contain the addresses in self
that are greater than the end
of other
, which will be empty if the ends of the ranges coincide.
sourcepub fn split_at(&self, split_start: u64) -> (AddressRange, AddressRange)
pub fn split_at(&self, split_start: u64) -> (AddressRange, AddressRange)
Returns the two subsets of this range split at the split_start
address.
If split_start
is not contained in this range, returns the original range and an empty
range.
sourcepub fn len(&self) -> Option<u64>
pub fn len(&self) -> Option<u64>
Computes the length of an AddressRange
.
Returns None
if the length cannot be represented in u64
(if the range is
0..=u64::MAX
).
fn log(&self, f: &mut Formatter<'_>) -> Result
Trait Implementations§
source§impl Clone for AddressRange
impl Clone for AddressRange
source§fn clone(&self) -> AddressRange
fn clone(&self) -> AddressRange
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for AddressRange
impl Debug for AddressRange
source§impl<'de> Deserialize<'de> for AddressRange
impl<'de> Deserialize<'de> for AddressRange
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl Display for AddressRange
impl Display for AddressRange
source§impl From<AddressRange> for RangeInclusive<u64>
impl From<AddressRange> for RangeInclusive<u64>
source§fn from(address_range: AddressRange) -> RangeInclusive<u64>
fn from(address_range: AddressRange) -> RangeInclusive<u64>
source§impl From<RangeInclusive<u64>> for AddressRange
impl From<RangeInclusive<u64>> for AddressRange
source§fn from(range: RangeInclusive<u64>) -> AddressRange
fn from(range: RangeInclusive<u64>) -> AddressRange
source§impl Ord for AddressRange
impl Ord for AddressRange
Custom comparison function that provides a total order over all possible AddressRange
values
and considers all empty ranges to be equal.
source§impl PartialEq<AddressRange> for AddressRange
impl PartialEq<AddressRange> for AddressRange
source§impl PartialOrd<AddressRange> for AddressRange
impl PartialOrd<AddressRange> for AddressRange
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more