Trait hal_core::Address

source ·
pub trait Address: Copy + Add<usize, Output = Self> + Sub<usize, Output = Self> + AddAssign<usize> + SubAssign<usize> + PartialEq + Eq + PartialOrd + Ord + Debug {
    // Required methods
    fn as_usize(self) -> usize;
    fn from_usize(u: usize) -> Self;

    // Provided methods
    fn align_up<A: Into<usize>>(self, align: A) -> Self { ... }
    fn align_up_for<T>(self) -> Self { ... }
    fn align_down<A: Into<usize>>(self, align: A) -> Self { ... }
    fn align_down_for<T>(self) -> Self { ... }
    fn offset(self, offset: i32) -> Self { ... }
    fn difference(self, other: Self) -> isize { ... }
    fn is_aligned<A: Into<usize>>(self, align: A) -> bool { ... }
    fn is_aligned_for<T>(self) -> bool { ... }
    fn as_ptr<T>(self) -> *mut T { ... }
}

Required Methods§

source

fn as_usize(self) -> usize

source

fn from_usize(u: usize) -> Self

Provided Methods§

source

fn align_up<A: Into<usize>>(self, align: A) -> Self

Aligns self up to align.

The specified alignment must be a power of two.

Panics
  • If align is not a power of two.
source

fn align_up_for<T>(self) -> Self

Align self up to the required alignment for a value of type T.

This is equivalent to

addr.align_up(core::mem::align_of::<T>())
source

fn align_down<A: Into<usize>>(self, align: A) -> Self

Aligns self down to align.

The specified alignment must be a power of two.

Panics
  • If align is not a power of two.
source

fn align_down_for<T>(self) -> Self

Align self down to the required alignment for a value of type T.

This is equivalent to

addr.align_down(core::mem::align_of::<T>())
source

fn offset(self, offset: i32) -> Self

Offsets this address by offset.

If the specified offset would overflow, this function saturates instead.

source

fn difference(self, other: Self) -> isize

Returns the difference between self and other.

source

fn is_aligned<A: Into<usize>>(self, align: A) -> bool

Returns true if self is aligned on the specified alignment.

Notes

align must be a power of two. This is asserted in debug builds.

source

fn is_aligned_for<T>(self) -> bool

Returns true if self is aligned on the alignment of the specified type.

source

fn as_ptr<T>(self) -> *mut T

Panics
  • If self is not aligned for a T-typed value.

Object Safety§

This trait is not object safe.

Implementors§