Skip to main content

CompactDynamicLayout

Trait CompactDynamicLayout 

Source
pub trait CompactDynamicLayout:
    Sized
    + Copy
    + Pod {
    const DISC: u8;
    const FIXED_HEAD_SIZE: usize = _;
    const MIN_LEN: usize = _;
    const TAIL_OFFSET: usize = Self::MIN_LEN;

    // Provided method
    fn validate_compact_dynamic(data: &[u8]) -> ProgramResult { ... }
}
Expand description

A compact account with a fixed zero-copy head followed by a dynamic tail:

byte 0            : disc (u8)
bytes 1..1+H      : fixed head (this Pod struct), H = size_of::<Self>()
bytes 1+H..       : dynamic tail (u32 LE length prefix + payload)

This is the 1-byte-header analogue of the headered dynamic_tail layout: it gives an account a Quasar-class [disc][fixed_head][tail] shape with no 16-byte universal header, while keeping Hopper’s registry, schema, and fingerprint tooling.

Unlike CompactLayout, the wire length is not fixed, the tail may be empty or grow via resize. The fixed head is still overlaid zero-copy at COMPACT_BODY_OFFSET; the tail is read/written through the macro-generated tail_* helpers, which operate on a length-prefixed payload anchored at Self::TAIL_OFFSET (the same offset-parameterized read_tail/write_tail runtime the headered path uses).

§Safety

As with CompactLayout, the fixed head is overlaid directly on account bytes starting at COMPACT_BODY_OFFSET; the Pod supertrait carries the alignment-1 / no-padding / valid-for-all-bits obligation for that head. The tail bytes beyond the head are never reinterpreted as Self.

Required Associated Constants§

Source

const DISC: u8

Discriminator stored at byte 0 of the account.

Provided Associated Constants§

Source

const FIXED_HEAD_SIZE: usize = _

Fixed head size in bytes (the zero-copy struct), excluding the discriminator and the tail.

Source

const MIN_LEN: usize = _

Minimum wire length: 1 discriminator byte + the fixed head. The tail may be empty, so this is the floor, not the exact length.

Source

const TAIL_OFFSET: usize = Self::MIN_LEN

Byte offset of the tail region (its u32 LE length prefix), immediately after the fixed head. Equal to Self::MIN_LEN.

Provided Methods§

Source

fn validate_compact_dynamic(data: &[u8]) -> ProgramResult

Validate that data is a compact-dynamic account of this type: it is at least MIN_LEN bytes (discriminator + fixed head present) and the discriminator at byte 0 matches.

Deliberately does not require an exact length: trailing tail bytes are expected. The tail’s own length prefix and payload bounds are validated by the tail accessors when used.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§