tiny.zen.FrontmatterStorage
Defined in tiny.zen.
API (18)
Actions
Public operations.
Types and contracts
Public types and contracts.
Fields and members
Public fields and members.
Source
Source: lib/zen/src/frontmatter/storage.zig:21
zig
pub const Storage = struct { phase: alloc_phase.capacity.Phase, capacity: capacity_mod.Capacity, bytes: []align(capacity_mod.storage_alignment) u8, pairs: []model.Pair, continuation: []u8, in_use: bool = false, pub const Limits: type = capacity_mod.Limits; pub const Capacity: type = capacity_mod.Capacity; pub const Exhaustion: type = model.Exhaustion; pub const InitError = std.mem.Allocator.Error || capacity_mod.DeriveError; pub const AcquireError: type = model.Error; pub const claim: alloc_phase.capacity.Declaration = .{ .source = .{ .id = "zen.frontmatter_storage", .kind = .phase_static, .limit_source = .caller, .storage = .{ .covered = &.{ .{ .id = "frontmatter_pair_descriptors", .lifetime = .steady, .detail = "frontmatter pair descriptors", }, .{ .id = "joined_continuation_values", .lifetime = .steady, .detail = "joined continuation values", }, }, .excluded = &.{ "caller-owned Markdown source and borrowed ordinary metadata values", "site catalog, rendered page, theme, and filesystem output owners", }, }, .capacity = .{ .inputs = &.{ alloc_phase.capacity.bindInput(Limits, "max_pairs", "max_pairs"), alloc_phase.capacity.bindInput(Limits, "max_continuation_bytes", "max_continuation_bytes"), }, .type_selectors = &.{ alloc_phase.capacity.bindType(model.Pair, "pair"), }, .nodes = &.{ .{ .input = 0 }, .{ .scale = .{ .node = 0, .coefficient = .{ .size_of_concrete_type = 0 } } }, .{ .alignment = .{ .node = 1, .alignment = .{ .literal = 16 } } }, .{ .input = 1 }, .{ .add = .{ .left = 2, .right = 3 } }, }, .assertions = &.{.{ .scope = .closure_total, .measure = .retained, .relation = .exact, .expression = 4, }}, }, .overload = .{ .kind = .reject_before_mutation, .detail = "unclosed input, pair overflow, continuation overflow, and concurrent acquisition fail before storage mutation", }, .risks = .{ .transitive = .{ .status = .witnessed, .detail = "section discovery, field scanning, and continuation joining use only borrowed input and acquired slices", }, .foreign = .{ .status = .excluded, .detail = "frontmatter parsing crosses no operating-system or foreign callback boundary", }, }, .obligations = &.{ .{ .key = "zen_frontmatter_capacity", .role = .capacity_model }, .{ .key = "zen_frontmatter_acquisition", .role = .custom }, .{ .key = "zen_frontmatter_oom", .role = .custom }, .{ .key = "zen_frontmatter_boundaries", .role = .overload }, .{ .key = "zen_frontmatter_reuse", .role = .overload }, .{ .key = "zen_frontmatter_sealed", .role = .transitive_risk }, .{ .key = "zen_frontmatter_root", .role = .custom }, .{ .key = "zen_frontmatter_consumer", .role = .foreign_risk }, }, }, .bindings = .{ .owner = @This(), .seal = .{ .family = alloc_phase.capacity.selector(@This().activate), .premise = .{ .class = .checked_semantic_fact, .authority = .checker, }, }, .teardown = .{ .family = alloc_phase.capacity.selector(@This().deinit), .premise = .{ .class = .checked_semantic_fact, .authority = .checker, }, }, }, }; pub fn init(allocator: std.mem.Allocator, limits: Limits) InitError!Storage { const capacity = try Capacity.derive(limits); const bytes = try allocator.alignedAlloc( u8, .fromByteUnits(capacity_mod.storage_alignment), capacity.storage_bytes, ); return .{ .phase = .initialization, .capacity = capacity, .bytes = bytes, .pairs = typedSlice( model.Pair, bytes, capacity.pairs_offset, limits.max_pairs, ), .continuation = bytes[capacity.continuation_offset..][0..limits.max_continuation_bytes], }; } pub fn activate(self: *Storage) void { std.debug.assert(self.phase == .initialization); std.debug.assert(self.bytes.len == self.capacity.storage_bytes); self.phase = .steady; } pub fn acquire(self: *Storage, markdown: []const u8) AcquireError!Regions { std.debug.assert(self.phase == .steady); if (self.in_use) return error.FrontmatterStorageInUse; const plan = try plan_mod.Plan.inspect(markdown, self.capacity.limits); self.in_use = true; return .{ .plan = plan, .pairs = self.pairs[0..plan.pairs], .continuation = self.continuation[0..plan.continuation_bytes], }; } pub fn reset(self: *Storage) void { std.debug.assert(self.phase == .steady); std.debug.assert(self.in_use); self.in_use = false; } pub fn status(self: *const Storage) Status { return .{ .phase = self.phase, .in_use = self.in_use, .storage_bytes = self.capacity.storage_bytes, .max_pairs = self.capacity.limits.max_pairs, .max_continuation_bytes = self.capacity.limits.max_continuation_bytes, }; } pub fn deinit(self: *Storage, allocator: std.mem.Allocator) void { std.debug.assert(self.phase != .teardown); std.debug.assert(!self.in_use); std.debug.assert(self.bytes.len == self.capacity.storage_bytes); self.phase = .teardown; allocator.free(self.bytes); self.bytes = &.{}; self.pairs = &.{}; self.continuation = &.{}; }};Source: lib/zen/src/root.zig:102
zig
/// Reusable caller-allocated storage for one parsed frontmatter block.pub const FrontmatterStorage = frontmatter.Storage;Also reachable as
Audit
| Definitions | 13 |
|---|---|
| Public names | 26 |
| Members | 6 |
| Version | 26.7.0 |
| Revision | daab053ee433 |