nstd_core_mem_align

Function nstd_core_mem_align 

Source
#[unsafe(no_mangle)]
pub unsafe extern "C" fn nstd_core_mem_align( ptr: NSTDAny, align: NSTDUInt, ) -> NSTDAny
Available on crate feature core only.
Expand description

Returns a pointer that is properly aligned to align based on the offset ptr.

§Parameters:

  • NSTDAny ptr - The pointer to align.

  • NSTDUInt align - The alignment requirement. This must be a power of two.

§Returns

NSTDAny aligned - The properly aligned pointer.

§Panics

This operation will panic if align is not a power of two or overflow occurs.

§Safety

Both ptr and the resulting pointer must be either in bounds or one byte past the end of the same allocated object.

§Example

use nstd_sys::core::mem::{nstd_core_mem_align, nstd_core_mem_is_aligned};

unsafe {
    let ptr = 2 as _;
    let aligned = nstd_core_mem_align(ptr, 16);
    assert!(nstd_core_mem_is_aligned(aligned, 16));
}