pub struct Span { /* private fields */ }Expand description
Represents an interval of memory [base, acme)
Use get_base_acme to retrieve base and acme directly.
§Empty Spans
Note that where base >= acme, the Span is considered empty, in which case
the specific values of base and acme are considered meaningless.
- Most functions will no-op or return
Nonefor empty spans (check the docs). - Empty spans contain nothing and overlap with nothing.
- Empty spans are contained by all sized spans.
Implementations§
Source§impl Span
impl Span
Sourcepub const fn get_base_acme(self) -> Option<(usize, usize)>
pub const fn get_base_acme(self) -> Option<(usize, usize)>
If self isn’t empty, returns (base, acme)
Sourcepub const fn from_base_size(base: usize, size: usize) -> Self
pub const fn from_base_size(base: usize, size: usize) -> Self
pub fn from_ptr_size(ptr: *mut u8, size: usize) -> Self
Sourcepub const fn contains(self, addr: usize) -> bool
pub const fn contains(self, addr: usize) -> bool
Returns whether self contains addr.
Empty spans contain nothing.
Sourcepub fn contains_ptr(self, ptr: *mut u8) -> bool
pub fn contains_ptr(self, ptr: *mut u8) -> bool
Returns whether self contains ptr.
Empty spans contain nothing.
Sourcepub const fn contains_span(self, other: Span) -> bool
pub const fn contains_span(self, other: Span) -> bool
Returns whether self contains other.
Empty spans are contained by any span, even empty ones.
Sourcepub const fn overlaps(self, other: Span) -> bool
pub const fn overlaps(self, other: Span) -> bool
Returns whether some of self overlaps with other.
Empty spans don’t overlap with anything.
Sourcepub const fn word_align_inward(self) -> Self
pub const fn word_align_inward(self) -> Self
Aligns base upward and acme downward by align_of::<usize>().
Sourcepub const fn word_align_outward(self) -> Self
pub const fn word_align_outward(self) -> Self
Aligns base downward and acme upward by align_of::<usize>().
Sourcepub const fn fit_within(self, other: Span) -> Self
pub const fn fit_within(self, other: Span) -> Self
Returns a span that other contains by raising base or lowering acme.
If other is empty, returns other.
Sourcepub const fn fit_over(self, other: Self) -> Self
pub const fn fit_over(self, other: Self) -> Self
Returns a span that contains other by extending self.
If other is empty, returns self, as all spans contain any empty span.