Skip to main content

Alignable

Trait Alignable 

Source
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§

Source

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
Source

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
Source

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".

Implementations on Foreign Types§

Source§

impl Alignable for u8

Source§

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

Source§

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

Source§

fn prev_power_of_two(self) -> u8

Source§

impl Alignable for u16

Source§

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

Source§

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

Source§

fn prev_power_of_two(self) -> u16

Source§

impl Alignable for u32

Source§

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

Source§

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

Source§

fn prev_power_of_two(self) -> u32

Source§

impl Alignable for u64

Source§

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

Source§

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

Source§

fn prev_power_of_two(self) -> u64

Source§

impl Alignable for usize

Implementors§