pub trait LayoutExt {
// Required methods
fn repeat(&self, n: usize) -> Result<(Layout, usize), LayoutError>;
fn padding_needed_for(&self, align: usize) -> usize;
}
Expand description
Extension trait for the Layout
type that copies useful nightly functions so that we can use
them on stable.
Required Methods§
fn repeat(&self, n: usize) -> Result<(Layout, usize), LayoutError>
fn repeat(&self, n: usize) -> Result<(Layout, usize), LayoutError>
Creates a layout describing the record for n
instances of
self
, with a suitable amount of padding between each to
ensure that each instance is given its requested size and
alignment. On success, returns (k, offs)
where k
is the
layout of the array and offs
is the distance between the start
of each element in the array.
On arithmetic overflow, returns LayoutError
.
fn padding_needed_for(&self, align: usize) -> usize
fn padding_needed_for(&self, align: usize) -> usize
to ensure that the following address will satisfy align
(measured in bytes).
e.g., if self.size()
is 9, then self.padding_needed_for(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.
Note that the utility of the returned value requires align
to be less than or equal to the alignment of the starting
address for the whole allocated block of memory. One way to
satisfy this constraint is to ensure align <= self.align()
.