talloc

Struct Span

Source
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 None for 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

Source

pub const fn is_empty(self) -> bool

Returns whether base >= acme.

Source

pub const fn is_sized(self) -> bool

Returns whether base < acme.

Source

pub const fn size(self) -> usize

Returns the size of the span, else zero if base >= span.

Source

pub const fn get_base_acme(self) -> Option<(usize, usize)>

If self isn’t empty, returns (base, acme)

Source

pub const fn empty() -> Self

Create an empty span.

Source

pub const fn new(base: usize, acme: usize) -> Self

Create a new span.

Source

pub const fn from_base_size(base: usize, size: usize) -> Self

Creates a Span given a base and a size.

§Panics

Panics if base + size overflows.

Source

pub fn from_ptr_size(ptr: *mut u8, size: usize) -> Self

Source

pub const fn to_ptr_range(self) -> Option<Range<*mut u8>>

Returns None if self is empty.

Source

pub const fn to_slice(self) -> Option<*mut [u8]>

Returns None if self is empty.

Source

pub const fn contains(self, addr: usize) -> bool

Returns whether self contains addr.

Empty spans contain nothing.

Source

pub fn contains_ptr(self, ptr: *mut u8) -> bool

Returns whether self contains ptr.

Empty spans contain nothing.

Source

pub const fn contains_span(self, other: Span) -> bool

Returns whether self contains other.

Empty spans are contained by any span, even empty ones.

Source

pub const fn overlaps(self, other: Span) -> bool

Returns whether some of self overlaps with other.

Empty spans don’t overlap with anything.

Source

pub const fn word_align_inward(self) -> Self

Aligns base upward and acme downward by align_of::<usize>().

Source

pub const fn word_align_outward(self) -> Self

Aligns base downward and acme upward by align_of::<usize>().

Source

pub const fn above(self, min: usize) -> Self

Raises base if base is smaller than min.

Source

pub const fn below(self, max: usize) -> Self

Lowers acme if acme is greater than max.

Source

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.

Source

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.

Source

pub const fn extend(self, low: usize, high: usize) -> Self

Lower base by low and raise acme by high.

Does nothing if self is empty.

§Panics

Panics if lowering base by low or raising acme by high under/overflows.

Source

pub const fn truncate(self, low: usize, high: usize) -> Span

Raise base by low and lower acme by high.

If self is empty, self is returned.

Trait Implementations§

Source§

impl Clone for Span

Source§

fn clone(&self) -> Span

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Span

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Span

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for Span

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<&mut [u8]> for Span

Source§

fn from(value: &mut [u8]) -> Self

Converts to this type from the input type.
Source§

impl From<*mut [u8]> for Span

Source§

fn from(value: *mut [u8]) -> Self

Converts to this type from the input type.
Source§

impl From<Range<*mut u8>> for Span

Source§

fn from(value: Range<*mut u8>) -> Self

Converts to this type from the input type.
Source§

impl From<Range<usize>> for Span

Source§

fn from(value: Range<usize>) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Span

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Span

Source§

impl Eq for Span

Auto Trait Implementations§

§

impl Freeze for Span

§

impl RefUnwindSafe for Span

§

impl Send for Span

§

impl Sync for Span

§

impl Unpin for Span

§

impl UnwindSafe for Span

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.