tiny.zen.ThemeRenderStorage
Defined in tiny.zen.
API (19)
Actions
Public operations.
Types and contracts
Public types and contracts.
Fields and members
Public fields and members.
Source
Source: lib/zen/src/theme/storage.zig:22
zig
pub const Storage = struct { phase: alloc_phase.capacity.Phase, capacity: capacity_mod.Capacity, bytes: []u8, in_use: bool = false, output_bytes: usize = 0, high_water_output_bytes: usize = 0, rejected_page_count: u64 = 0, pub const Limits: type = capacity_mod.Limits; pub const Capacity: type = capacity_mod.Capacity; pub const Exhaustion: type = model.Exhaustion; pub const InitError: type = std.mem.Allocator.Error; pub const AcquireError: type = model.Error; pub const claim: alloc_phase.capacity.Declaration = .{ .source = .{ .id = "zen.theme_render_storage", .kind = .phase_static, .limit_source = .caller, .storage = .{ .covered = &.{ .{ .id = "rendered_theme_page_bytes", .lifetime = .steady, .detail = "rendered theme page bytes", }, }, .excluded = &.{ "caller-owned theme layout, page values, metadata, and includes", "Markdown rendering, site catalog, loaded theme files, and filesystem owners", }, }, .capacity = .{ .inputs = &.{ alloc_phase.capacity.bindInput(Limits, "max_output_bytes", "max_output_bytes"), }, .type_selectors = &.{}, .nodes = &.{ .{ .input = 0 }, }, .assertions = &.{.{ .scope = .closure_total, .measure = .retained, .relation = .exact, .expression = 0, }}, }, .overload = .{ .kind = .reject_before_mutation, .detail = "invalid templates, max plus one output, and in-use rendering reject before output bytes or the active result change; only rejection telemetry advances", }, .risks = .{ .transitive = .{ .status = .witnessed, .detail = "template scanning, placeholder resolution, escaped-length planning, and exact filling use borrowed inputs and the acquired byte slice only", }, .foreign = .{ .status = .excluded, .detail = "theme page rendering crosses no operating-system or foreign callback boundary", }, }, .obligations = &.{ .{ .key = "zen_theme_render_capacity", .role = .capacity_model }, .{ .key = "zen_theme_render_acquisition", .role = .custom }, .{ .key = "zen_theme_render_oom", .role = .custom }, .{ .key = "zen_theme_render_boundaries", .role = .overload }, .{ .key = "zen_theme_render_reuse", .role = .overload }, .{ .key = "zen_theme_render_sealed", .role = .transitive_risk }, .{ .key = "zen_theme_render_root", .role = .custom }, .{ .key = "zen_theme_render_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 = Capacity.derive(limits); const bytes = if (capacity.storage_bytes == 0) @as([]u8, &.{}) else try allocator.alloc(u8, capacity.storage_bytes); return .{ .phase = .initialization, .capacity = capacity, .bytes = bytes, }; } pub fn activate(self: *Storage) void { std.debug.assert(self.phase == .initialization); self.assertStorage(); self.phase = .steady; } pub fn acquire(self: *Storage, active: model.Theme, page: model.Page) AcquireError!Regions { std.debug.assert(self.phase == .steady); if (self.in_use) return self.reject(error.ThemeStorageInUse); const plan = plan_mod.Plan.inspect(active, page, self.capacity.limits) catch |err| { self.rejected_page_count +|= 1; return err; }; self.in_use = true; self.output_bytes = plan.output_bytes; self.high_water_output_bytes = @max(self.high_water_output_bytes, plan.output_bytes); self.assertStorage(); return .{ .plan = plan, .output = self.bytes[self.capacity.output_offset..][0..plan.output_bytes], }; } pub fn reset(self: *Storage) void { std.debug.assert(self.phase == .steady); std.debug.assert(self.in_use); self.in_use = false; self.output_bytes = 0; self.assertStorage(); } pub fn status(self: *const Storage) Status { return .{ .phase = self.phase, .in_use = self.in_use, .storage_bytes = self.capacity.storage_bytes, .max_output_bytes = self.capacity.limits.max_output_bytes, .output_bytes = self.output_bytes, .high_water_output_bytes = self.high_water_output_bytes, .rejected_page_count = self.rejected_page_count, }; } pub fn deinit(self: *Storage, allocator: std.mem.Allocator) void { std.debug.assert(self.phase != .teardown); std.debug.assert(!self.in_use); self.assertStorage(); self.phase = .teardown; allocator.free(self.bytes); self.bytes = &.{}; } fn reject(self: *Storage, err: model.Exhaustion) model.Exhaustion { self.rejected_page_count +|= 1; return err; } fn assertStorage(self: *const Storage) void { std.debug.assert(self.bytes.len == self.capacity.storage_bytes); std.debug.assert(self.output_bytes <= self.bytes.len); std.debug.assert(self.high_water_output_bytes <= self.bytes.len); if (!self.in_use) std.debug.assert(self.output_bytes == 0); }};Source: lib/zen/src/root.zig:251
zig
/// Reusable caller-allocated storage for one rendered themed page.pub const ThemeRenderStorage = theme.RenderStorage;Also reachable as
Audit
| Definitions | 13 |
|---|---|
| Public names | 26 |
| Members | 7 |
| Version | 26.7.0 |
| Revision | daab053ee433 |