Skip to main content

Alignable

Trait Alignable 

pub trait Alignable {
    // Required methods
    fn align_offset(self, align: Self) -> Self;
    fn align_up(self, align: Self) -> Self;
    fn prev_power_of_two(self) -> Self;
}
Expand description

This trait represents an alignable primitive integer value representing an address

Required Methods§

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

This function computes the offset, in bytes, needed to align self upwards so that it is aligned to align bytes.

The following must be true, or this function will panic:

  • align is non-zero
  • align is a power of two

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

This function aligns self to the specified alignment (in bytes), aligning upwards.

The following must be true, or this function will panic:

  • align is non-zero
  • align is a power of two
  • self + align must be less than Self::MAX

fn prev_power_of_two(self) -> Self

Compute the nearest power of two less than or equal to self

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§

§

impl Alignable for u8

§

fn align_offset(self, align: u8) -> u8

§

fn align_up(self, align: u8) -> u8

§

fn prev_power_of_two(self) -> u8

§

impl Alignable for u16

§

fn align_offset(self, align: u16) -> u16

§

fn align_up(self, align: u16) -> u16

§

fn prev_power_of_two(self) -> u16

§

impl Alignable for u32

§

fn align_offset(self, align: u32) -> u32

§

fn align_up(self, align: u32) -> u32

§

fn prev_power_of_two(self) -> u32

§

impl Alignable for u64

§

fn align_offset(self, align: u64) -> u64

§

fn align_up(self, align: u64) -> u64

§

fn prev_power_of_two(self) -> u64

§

impl Alignable for usize

§

fn align_offset(self, align: usize) -> usize

§

fn align_up(self, align: usize) -> usize

§

fn prev_power_of_two(self) -> usize

Implementors§