Skip to main content

Span

Struct Span 

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§

§

impl Span

pub fn is_empty(self) -> bool

Returns whether base >= acme.

pub fn is_sized(self) -> bool

Returns whether base < acme.

pub fn size(self) -> usize

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

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

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

pub const fn empty() -> Span

Create an empty span.

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

Create a new span.

pub const fn from_base_size(base: *mut u8, size: usize) -> Span

Creates a Span given a base and a size.

If base + size overflows, the result is empty.

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

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

👎Deprecated: Conversion from const references encourages UB. This will be removed in a future release.

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

Returns None if self is empty.

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

Returns None if self is empty.

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

Returns whether self contains addr.

Empty spans contain nothing.

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

Returns whether self contains other.

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

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

Returns whether some of self overlaps with other.

Empty spans don’t overlap with anything.

pub fn word_align_inward(self) -> Span

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

pub fn word_align_outward(self) -> Span

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

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

Raises base if base is smaller than min.

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

Lowers acme if acme is greater than max.

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

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.

pub fn fit_within(self, other: Span) -> Span

Returns a span that other contains by raising base or lowering acme.

If other is empty, returns other.

pub fn fit_over(self, other: Span) -> Span

Returns a span that contains other by extending self.

If other is empty, returns self, as all spans contain any empty span.

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

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.

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§

§

impl Clone for Span

§

fn clone(&self) -> Span

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

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

Performs copy-assignment from source. Read more
§

impl Debug for Span

§

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

Formats the value using the given formatter. Read more
§

impl Default for Span

§

fn default() -> Span

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

impl Display for Span

§

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

Formats the value using the given formatter. Read more
§

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

§

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

Converts to this type from the input type.
§

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

§

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

Converts to this type from the input type.
§

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

§

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

Converts to this type from the input type.
§

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

§

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

Converts to this type from the input type.
§

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

§

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

Converts to this type from the input type.
§

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

§

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

Converts to this type from the input type.
§

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

§

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

Converts to this type from the input type.
§

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

§

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

Converts to this type from the input type.
§

impl Hash for Span

§

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

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
§

impl PartialEq for Span

§

fn eq(&self, other: &Span) -> 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.
§

impl Copy for Span

§

impl Eq for Span

§

impl Send for Span

Auto Trait Implementations§

§

impl Freeze for Span

§

impl RefUnwindSafe for Span

§

impl !Sync for Span

§

impl Unpin for Span

§

impl UnsafeUnpin 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, dest: *mut u8)

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

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.