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.
- Empty spans contain nothing and overlap with nothing.
- Empty spans are contained by any sized span.
Implementations§
Source§impl Span
impl Span
Sourcepub fn get_base_acme(self) -> Option<(*mut u8, *mut u8)>
pub fn get_base_acme(self) -> Option<(*mut u8, *mut u8)>
If self
isn’t empty, returns (base, acme)
Sourcepub const fn from_base_size(base: *mut u8, size: usize) -> Self
pub const fn from_base_size(base: *mut u8, size: usize) -> Self
Creates a Span
given a base
and a size
.
If base + size
overflows, the result is empty.
pub const fn from_slice<T>(slice: *mut [T]) -> Self
pub const fn from_const_slice<T>(slice: *const [T]) -> Self
pub const fn from_array<T, const N: usize>(array: *mut [T; N]) -> Self
pub const fn from_const_array<T, const N: usize>(array: *const [T; N]) -> Self
Sourcepub fn contains(self, ptr: *mut u8) -> bool
pub fn contains(self, ptr: *mut u8) -> bool
Returns whether self
contains addr
.
Empty spans contain nothing.
Sourcepub fn contains_span(self, other: Span) -> bool
pub fn contains_span(self, other: Span) -> bool
Returns whether self
contains other
.
Empty spans are contained by any span, even empty ones.
Sourcepub fn overlaps(self, other: Span) -> bool
pub fn overlaps(self, other: Span) -> bool
Returns whether some of self
overlaps with other
.
Empty spans don’t overlap with anything.
Sourcepub fn word_align_inward(self) -> Self
pub fn word_align_inward(self) -> Self
Aligns base
upward and acme
downward by align_of::<usize>()
.
Sourcepub fn word_align_outward(self) -> Self
pub fn word_align_outward(self) -> Self
Aligns base
downward and acme
upward by align_of::<usize>()
.
Sourcepub fn except(self, exclude: Span) -> (Self, Self)
pub fn except(self, exclude: Span) -> (Self, Self)
Returns the Span
s of self
below and above the exclude
span, respectively.
Alternatively worded, the set difference self
\exclude
.
If exclude
is empty, self
and an empty Span
are returned.
Sourcepub fn fit_within(self, other: Span) -> Self
pub 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 fn fit_over(self, other: Self) -> Self
pub 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.