Skip to main content

LayoutManifest

Struct LayoutManifest 

Source
pub struct LayoutManifest {
    pub name: &'static str,
    pub version: u8,
    pub discriminator: u8,
    pub layout_id: [u8; 8],
    pub fields: &'static [FieldDescriptor],
    pub segments: &'static [SegmentFieldDescriptor],
}
Expand description

A complete account layout manifest (v1).

Describes the schema of one Jiminy account type: its name, version, discriminator, layout_id, and ordered field list. This is the structured equivalent of the hash input string used to compute LAYOUT_ID.

Fields§

§name: &'static str

Account type name (e.g., "Vault").

§version: u8

Schema version.

§discriminator: u8

Account discriminator byte.

§layout_id: [u8; 8]

Deterministic layout_id (first 8 bytes of SHA-256).

§fields: &'static [FieldDescriptor]

Ordered list of fields (including the header).

§segments: &'static [SegmentFieldDescriptor]

Optional list of dynamic segments (for segmented layouts).

Implementations§

Source§

impl LayoutManifest

Source

pub const fn total_size(&self) -> usize

Total size of the account in bytes (sum of all field sizes).

Source

pub const fn field_count(&self) -> usize

Number of fields in the layout.

Source

pub fn field_offset(&self, name: &str) -> Option<usize>

Find the byte offset of a field by name.

Returns None if the field name is not found.

Source

pub fn field(&self, name: &str) -> Option<&FieldDescriptor>

Find a field descriptor by name.

Source

pub fn hash_input(&self) -> String

Reconstruct the canonical hash input string.

This produces the same string that zero_copy_layout! uses to compute LAYOUT_ID, enabling verification that a manifest matches a compiled layout.

Source

pub fn export_json(&self) -> String

Export the manifest as a JSON string (no serde dependency).

Produces a self-contained JSON document suitable for TypeScript codegen, indexer ingestion, or cross-language tooling.

Source

pub fn verify(&self) -> Result<(), String>

Validate structural invariants of this manifest.

Returns Ok(()) if:

  • All field sizes are non-zero
  • The first field is a Header with size 16
  • No duplicate field names exist
  • total_size() equals the sum of field sizes

This does not recompute layout_id (that would require a SHA-256 dependency). Use hash_input() to verify the hash externally.

Source

pub fn verify_account(&self, data: &[u8]) -> Result<(), &'static str>

Verify that raw account data matches this manifest.

Checks:

  • Data length ≥ total_size()
  • Discriminator byte (offset 0) matches self.discriminator
  • Layout ID bytes (offsets 4..12) match self.layout_id

This is the runtime counterpart to verify() (which checks the manifest’s internal consistency). Use this to validate that on-chain data belongs to the expected account type.

Source

pub fn verify_hash(&self, full_sha256: &[u8; 32]) -> Result<(), &'static str>

Verify that a caller-provided SHA-256 hash is consistent with this manifest’s layout_id.

The caller computes SHA-256(self.hash_input()) using their own SHA-256 implementation and passes the full 32-byte digest here. This method checks that the first 8 bytes match self.layout_id, providing 256-bit collision resistance without adding a SHA-256 dependency to this crate.

Returns Ok(()) if the truncated hash matches, or an error message if it doesn’t.

Trait Implementations§

Source§

impl Clone for LayoutManifest

Source§

fn clone(&self) -> LayoutManifest

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for LayoutManifest

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for LayoutManifest

Source§

fn eq(&self, other: &LayoutManifest) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for LayoutManifest

Source§

impl StructuralPartialEq for LayoutManifest

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.