Skip to content
CryoCryo home
Stdliballoc

layout

import std::alloc::layout; · source

Layout

type struct Layout {
    size:      u64;
    alignment: u64;

    static new(size: u64, alignment: u64) -> Layout;
    static of<T>() -> Layout;
    static array<T>(count: u64) -> Layout;
    static try_array<T>(count: u64) -> Option<Layout>;
    size(&this) -> u64;
    alignment(&this) -> u64;
    padded_size(&this) -> u64;
}

Every Allocator call takes a Layout: a size and an alignment. Constructing one validates that the alignment is a non-zero power of two, so allocators downstream can rely on the invariant without re-checking it.

Constructor / methodNotes
new(size, alignment)Panics if alignment is zero or not a power of two — that's a caller bug, not a runtime condition. A zero size is allowed; the allocator decides what it means.
of<T>()The layout of a single T.
array<T>(count)count contiguous Ts. Panics on multiplication overflow.
try_array<T>(count)Option<Layout>None on overflow, for try_* constructors that must not panic.
size() / alignment()u64
padded_size()size rounded up to the next multiple of alignment — the stride for packing adjacent values.