Skip to main content

Align

Trait Align 

Source
pub trait Align<A = Self>: Copy + PartialEq {
    // Required methods
    fn align_down(self, align: A) -> Self;
    fn checked_align_up(self, align: A) -> Option<Self>;

    // Provided methods
    fn align_up(self, align: A) -> Self { ... }
    fn is_aligned_to(self, align: A) -> bool { ... }
}
Expand description

An adress that can be aligned.

Required Methods§

Source

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

Align address downwards.

Returns the greatest x with alignment align so that x <= addr.

Panics if the alignment is not a power of two.

Source

fn checked_align_up(self, align: A) -> Option<Self>

Checked align address upwards.

Returns the smallest x with alignment align so that x >= addr.

Returns None if an overflow occurs.

Panics if the alignment is not a power of two.

Provided Methods§

Source

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

Align address upwards.

Returns the smallest x with alignment align so that x >= addr.

Panics if the alignment is not a power of two or if an overflow occurs.

Source

fn is_aligned_to(self, align: A) -> bool

Checks whether the address has the demanded alignment.

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.

Implementations on Foreign Types§

Source§

impl Align for u8

Source§

fn align_down(self, align: Self) -> Self

Source§

fn checked_align_up(self, align: Self) -> Option<Self>

Source§

impl Align for u16

Source§

fn align_down(self, align: Self) -> Self

Source§

fn checked_align_up(self, align: Self) -> Option<Self>

Source§

impl Align for u32

Source§

fn align_down(self, align: Self) -> Self

Source§

fn checked_align_up(self, align: Self) -> Option<Self>

Source§

impl Align for u64

Source§

fn align_down(self, align: Self) -> Self

Source§

fn checked_align_up(self, align: Self) -> Option<Self>

Source§

impl Align for u128

Source§

fn align_down(self, align: Self) -> Self

Source§

fn checked_align_up(self, align: Self) -> Option<Self>

Source§

impl Align for usize

Source§

fn align_down(self, align: Self) -> Self

Source§

fn checked_align_up(self, align: Self) -> Option<Self>

Implementors§