hal_core

Trait Address

Source
pub trait Address:
    Copy
    + Add<usize, Output = Self>
    + Sub<usize, Output = Self>
    + AddAssign<usize>
    + SubAssign<usize>
    + PartialEq
    + Eq
    + PartialOrd
    + Ord
    + Debug {
Show 13 methods // 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: isize) -> 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) -> *const T { ... } fn as_mut_ptr<T>(self) -> *mut T { ... } fn as_non_null<T>(self) -> Option<NonNull<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: isize) -> Self

Offsets this address by offset bytes.

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) -> *const T

Converts this address into a const pointer to a value of type T.

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

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

Converts this address into a mutable pointer to a value of type T.

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

fn as_non_null<T>(self) -> Option<NonNull<T>>

Converts this address into a Option<NonNull<T>> from a VAddr, returning None if the address is null.

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

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§