Struct talloc::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<Span> for Span

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method 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 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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.