Function zerocopy::util::core_layout::padding_needed_for

source ·
pub(crate) const fn padding_needed_for(len: usize, align: NonZeroUsize) -> usize
Expand description

Returns the amount of padding we must insert after len bytes to ensure that the following address will satisfy align (measured in bytes).

e.g., if len is 9, then padding_needed_for(len, 4) returns 3, because that is the minimum number of bytes of padding required to get a 4-aligned address (assuming that the corresponding memory block starts at a 4-aligned address).

The return value of this function has no meaning if align is not a power-of-two.

§Panics

May panic if align is not a power of two.