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§
Provided Methods§
sourcefn align_up<A: Into<usize>>(self, align: A) -> Self
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.
sourcefn align_up_for<T>(self) -> Self
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>())
sourcefn align_down<A: Into<usize>>(self, align: A) -> Self
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.
sourcefn align_down_for<T>(self) -> Self
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>())
sourcefn offset(self, offset: i32) -> Self
fn offset(self, offset: i32) -> Self
Offsets this address by offset
.
If the specified offset would overflow, this function saturates instead.
sourcefn difference(self, other: Self) -> isize
fn difference(self, other: Self) -> isize
Returns the difference between self
and other
.
sourcefn is_aligned<A: Into<usize>>(self, align: A) -> bool
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.
sourcefn is_aligned_for<T>(self) -> bool
fn is_aligned_for<T>(self) -> bool
Returns true
if self
is aligned on the alignment of the specified
type.
Object Safety§
This trait is not object safe.