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 strAccount type name (e.g., "Vault").
version: u8Schema version.
discriminator: u8Account 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
impl LayoutManifest
Sourcepub const fn total_size(&self) -> usize
pub const fn total_size(&self) -> usize
Total size of the account in bytes (sum of all field sizes).
Sourcepub const fn field_count(&self) -> usize
pub const fn field_count(&self) -> usize
Number of fields in the layout.
Sourcepub fn field_offset(&self, name: &str) -> Option<usize>
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.
Sourcepub fn field(&self, name: &str) -> Option<&FieldDescriptor>
pub fn field(&self, name: &str) -> Option<&FieldDescriptor>
Find a field descriptor by name.
Sourcepub fn hash_input(&self) -> String
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.
Sourcepub fn export_json(&self) -> String
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.
Sourcepub fn verify(&self) -> Result<(), String>
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
Headerwith 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.
Sourcepub fn verify_account(&self, data: &[u8]) -> Result<(), &'static str>
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.
Sourcepub fn verify_hash(&self, full_sha256: &[u8; 32]) -> Result<(), &'static str>
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
impl Clone for LayoutManifest
Source§fn clone(&self) -> LayoutManifest
fn clone(&self) -> LayoutManifest
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more