tiny.zen.SitePathStorage
Defined in tiny.zen.
API (23)
Actions
Public operations.
Types and contracts
Public types and contracts.
Fields and members
Public fields and members.
bytescapacityhigh_water_public_path_byteshigh_water_target_path_bytesin_usephasepublic_pathpublic_path_bytesrejected_path_counttarget_pathtarget_path_bytes
Source
Source: lib/zen/src/site/path/storage.zig:27
zig
pub const Storage = struct { phase: alloc_phase.capacity.Phase, capacity: capacity_mod.Capacity, bytes: []u8, target_path: []u8, public_path: []u8, in_use: bool = false, target_path_bytes: usize = 0, public_path_bytes: usize = 0, high_water_target_path_bytes: usize = 0, high_water_public_path_bytes: usize = 0, rejected_path_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 = std.mem.Allocator.Error || capacity_mod.DeriveError; pub const AcquireError: type = model.Error; pub const claim: alloc_phase.capacity.Declaration = .{ .source = .{ .id = "zen.site_path_storage", .kind = .phase_static, .limit_source = .caller, .storage = .{ .covered = &.{ .{ .id = "markdown_target_path_bytes", .lifetime = .steady, .detail = "Markdown target path bytes", }, .{ .id = "public_page_or_clean_url_path_bytes", .lifetime = .steady, .detail = "public page or clean URL path bytes", }, }, .excluded = &.{ "caller-owned relative paths and build roots", "retained site catalog strings, file contents, rendered pages, and filesystem internals", }, }, .capacity = .{ .inputs = &.{ alloc_phase.capacity.bindInput(Limits, "max_target_path_bytes", "max_target_path_bytes"), alloc_phase.capacity.bindInput(Limits, "max_public_path_bytes", "max_public_path_bytes"), }, .type_selectors = &.{}, .nodes = &.{ .{ .input = 0 }, .{ .input = 1 }, .{ .add = .{ .left = 0, .right = 1 } }, }, .assertions = &.{.{ .scope = .closure_total, .measure = .retained, .relation = .exact, .expression = 2, }}, }, .overload = .{ .kind = .reject_before_mutation, .detail = "max plus one and in-use requests reject before either reusable path region changes; only rejection telemetry advances", }, .risks = .{ .transitive = .{ .status = .witnessed, .detail = "planning and path filling use borrowed relative paths plus the two acquired byte regions only", }, .foreign = .{ .status = .excluded, .detail = "path transformation crosses no operating-system boundary; directory and file effects remain site-build consumers", }, }, .obligations = &.{ .{ .key = "zen_site_path_capacity", .role = .capacity_model }, .{ .key = "zen_site_path_acquisition", .role = .custom }, .{ .key = "zen_site_path_oom", .role = .custom }, .{ .key = "zen_site_path_boundaries", .role = .overload }, .{ .key = "zen_site_path_reuse", .role = .overload }, .{ .key = "zen_site_path_sealed", .role = .transitive_risk }, .{ .key = "zen_site_path_root", .role = .custom }, .{ .key = "zen_site_path_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 = if (capacity.storage_bytes == 0) @as([]u8, &.{}) else try allocator.alloc(u8, capacity.storage_bytes); return .{ .phase = .initialization, .capacity = capacity, .bytes = bytes, .target_path = bytes[capacity.target_path_offset..][0..limits.max_target_path_bytes], .public_path = bytes[capacity.public_path_offset..][0..limits.max_public_path_bytes], }; } pub fn activate(self: *Storage) void { std.debug.assert(self.phase == .initialization); self.assertStorage(); self.phase = .steady; } pub fn acquire( self: *Storage, relative_path: []const u8, clean_urls: bool, kind: model.PublicKind, ) AcquireError!Paths { std.debug.assert(self.phase == .steady); if (self.in_use) return self.reject(error.SitePathStorageInUse); const plan = plan_mod.Plan.inspect( relative_path, clean_urls, kind, self.capacity.limits, ) catch |err| { self.rejected_path_count +|= 1; return err; }; self.in_use = true; self.target_path_bytes = plan.target_path_bytes; self.public_path_bytes = plan.public_path_bytes; self.high_water_target_path_bytes = @max( self.high_water_target_path_bytes, plan.target_path_bytes, ); self.high_water_public_path_bytes = @max( self.high_water_public_path_bytes, plan.public_path_bytes, ); const target = transform.writeTarget( self.target_path[0..plan.target_path_bytes], relative_path, clean_urls, ); const public = transform.writePublic( self.public_path[0..plan.public_path_bytes], target, clean_urls, kind, ); self.assertStorage(); return .{ .target = target, .public = public }; } pub fn reset(self: *Storage) void { std.debug.assert(self.phase == .steady); std.debug.assert(self.in_use); self.in_use = false; self.target_path_bytes = 0; self.public_path_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_target_path_bytes = self.capacity.limits.max_target_path_bytes, .max_public_path_bytes = self.capacity.limits.max_public_path_bytes, .target_path_bytes = self.target_path_bytes, .public_path_bytes = self.public_path_bytes, .high_water_target_path_bytes = self.high_water_target_path_bytes, .high_water_public_path_bytes = self.high_water_public_path_bytes, .rejected_path_count = self.rejected_path_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 = &.{}; self.target_path = &.{}; self.public_path = &.{}; } fn reject(self: *Storage, err: model.Exhaustion) model.Exhaustion { self.rejected_path_count +|= 1; return err; } fn assertStorage(self: *const Storage) void { std.debug.assert(self.bytes.len == self.capacity.storage_bytes); std.debug.assert(self.target_path.len == self.capacity.limits.max_target_path_bytes); std.debug.assert(self.public_path.len == self.capacity.limits.max_public_path_bytes); std.debug.assert(self.target_path_bytes <= self.target_path.len); std.debug.assert(self.public_path_bytes <= self.public_path.len); std.debug.assert(self.high_water_target_path_bytes <= self.target_path.len); std.debug.assert(self.high_water_public_path_bytes <= self.public_path.len); if (!self.in_use) { std.debug.assert(self.target_path_bytes == 0); std.debug.assert(self.public_path_bytes == 0); } }};Source: lib/zen/src/root.zig:332
zig
/// Reusable caller-allocated target-path and public-URL storage.pub const SitePathStorage = site_path.Storage;Also reachable as
Audit
| Definitions | 13 |
|---|---|
| Public names | 26 |
| Members | 11 |
| Version | 26.7.0 |
| Revision | daab053ee433 |