Struct talc::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.

  • Empty spans contain nothing and overlap with nothing.
  • Empty spans are contained by any sized span.

Implementations§

source§

impl Span

source

pub fn is_empty(self) -> bool

Returns whether base >= acme.

source

pub fn is_sized(self) -> bool

Returns whether base < acme.

source

pub fn size(self) -> usize

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

source

pub fn get_base_acme(self) -> Option<(*mut u8, *mut u8)>

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

source

pub const fn empty() -> Self

Create an empty span.

source

pub const fn new(base: *mut u8, acme: *mut u8) -> Self

Create a new span.

source

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.

source

pub const fn from_slice<T>(slice: *mut [T]) -> Self

source

pub const fn from_const_slice<T>(slice: *const [T]) -> Self

source

pub const fn from_array<T, const N: usize>(array: *mut [T; N]) -> Self

source

pub const fn from_const_array<T, const N: usize>(array: *const [T; N]) -> Self

source

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

Returns None if self is empty.

source

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

Returns None if self is empty.

source

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

Returns whether self contains addr.

Empty spans contain nothing.

source

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

Returns whether self contains other.

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

source

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

Returns whether some of self overlaps with other.

Empty spans don’t overlap with anything.

source

pub fn word_align_inward(self) -> Self

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

source

pub fn word_align_outward(self) -> Self

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

source

pub fn above(self, min: *mut u8) -> Self

Raises base if base is smaller than min.

source

pub fn below(self, max: *mut u8) -> Self

Lowers acme if acme is greater than max.

source

pub fn except(self, exclude: Span) -> (Self, Self)

Returns the Spans 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.

source

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.

source

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.

source

pub 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 fn truncate(self, low: usize, high: usize) -> Span

Raise base by low and lower acme by high.

If self is empty, self is returned.

If either operation would wrap around the address space, an empty span 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<T> From<&[T]> for Span

source§

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

Converts to this type from the input type.
source§

impl<T, const N: usize> From<&[T; N]> for Span

source§

fn from(value: &[T; N]) -> Self

Converts to this type from the input type.
source§

impl<T> From<&mut [T]> for Span

source§

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

Converts to this type from the input type.
source§

impl<T, const N: usize> From<&mut [T; N]> for Span

source§

fn from(value: &mut [T; N]) -> Self

Converts to this type from the input type.
source§

impl<T> From<*const [T]> for Span

source§

fn from(value: *const [T]) -> Self

Converts to this type from the input type.
source§

impl<T, const N: usize> From<*const [T; N]> for Span

source§

fn from(value: *const [T; N]) -> Self

Converts to this type from the input type.
source§

impl<T> From<*mut [T]> for Span

source§

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

Converts to this type from the input type.
source§

impl<T, const N: usize> From<*mut [T; N]> for Span

source§

fn from(value: *mut [T; N]) -> Self

Converts to this type from the input type.
source§

impl<T> From<Range<*const T>> for Span

source§

fn from(value: Range<*const T>) -> Self

Converts to this type from the input type.
source§

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

source§

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

Converts to this type from the input type.
source§

impl Hash for Span

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl PartialEq 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

source§

impl Send for Span

Auto Trait Implementations§

§

impl Freeze for Span

§

impl RefUnwindSafe 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> 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>,

§

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>,

§

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.