tiny.preserves.symbols
Defined in tiny.preserves.
Named constants for the symbols the package builds and matches: protocol record labels, null, and the pattern wire form.
API (19)
Types and contracts
Public types and contracts.
Symbol: A symbol's name, held as a byte slice.
Values and defaults
Public values and defaults.
SYM_ARR: The labelarrof<arr>, the type of a group that matches sequences.SYM_BIND_PAT: The labelbindof the<bind P>record, the wire form of a capture.SYM_DICT: The labeldictof<dict>, the type of a group that matches dictionaries.SYM_DISCARD: The symbol_, the wire form of the discard pattern, alone or as the record<_>.SYM_ENTITY_RUNTIME: The labelEntityRuntime, whichentityRuntimeRecordwrites.SYM_GROUP: The labelgroupof the<group type {…}>record, the wire form of a record, sequence or dictionary pattern.SYM_LIT: The labellitof the<lit v>record, which matches the valuevitself.SYM_NULL: The symbolnull, the value the package uses for JSON's null.SYM_OBSERVE: The labelObserveof the<Observe pattern observer>record.SYM_REACTOR_ERROR: The labelReactorError, whichreactorErrorRecordwrites.SYM_REC: The labelrecof<rec L>, the type of a group that matches records labeledL.SYM_REQUIRE_SERVICE: The labelRequireService, whichrequireServiceRecordwrites.SYM_RESTART_SERVICE: The labelRestartService, whichrestartServiceRecordwrites.SYM_RUN_SERVICE: The labelRunService, whichrunServiceRecordwrites.SYM_SERVICE_DEPENDENCY: The labelServiceDependency, whichserviceDependencyRecordwrites.SYM_SERVICE_OBJECT: The labelServiceObject, whichserviceObjectRecordwrites.SYM_SERVICE_STATE: The labelServiceState, whichserviceStateRecordwrites.SYM_SYNCED: The labelSynced, whichsyncedRecordwrites.
Source
Source: lib/preserves/src/root.zig:109
zig
pub const symbols = @import("symbols.zig");Source: lib/preserves/src/symbols.zig
zig
//! Named constants for the symbols the package builds and matches: protocol record labels, `null`,//! and the pattern wire form. A builder and a matcher of the same record have to spell its label//! the same way, so both read it from one constant.const std = @import("std");/// A symbol's name, held as a byte slice. The package root's `isRecord` takes a label as one, and/// `symbolEql` compares one with a symbol's bytes. The struct is a separate type from a symbol/// value (`Value.symbol`), and the constants here are of this type.pub const Symbol = struct { /// The symbol's bytes. Every constant in this file points at a string literal, so the bytes /// live for the whole program. name: []const u8, /// Returns true when `a` and `b` have the same bytes. The file's test is its one caller. pub fn eql(a: Symbol, b: Symbol) bool { return std.mem.eql(u8, a.name, b.name); } /// Returns the byte order of `a`'s name against `b`'s. The file's test is its one caller. pub fn order(a: Symbol, b: Symbol) std.math.Order { return std.mem.order(u8, a.name, b.name); }};/// The label `Observe` of the `<Observe pattern observer>` record. `observeRecord` writes it, and/// `isObserve`, `observePattern` and `observeObserver` match on it.pub const SYM_OBSERVE = Symbol{ .name = "Observe" };/// The label `Synced`, which `syncedRecord` writes.pub const SYM_SYNCED = Symbol{ .name = "Synced" };/// The label `RequireService`, which `requireServiceRecord` writes.pub const SYM_REQUIRE_SERVICE = Symbol{ .name = "RequireService" };/// The label `RunService`, which `runServiceRecord` writes.pub const SYM_RUN_SERVICE = Symbol{ .name = "RunService" };/// The label `ServiceState`, which `serviceStateRecord` writes.pub const SYM_SERVICE_STATE = Symbol{ .name = "ServiceState" };/// The label `ServiceObject`, which `serviceObjectRecord` writes.pub const SYM_SERVICE_OBJECT = Symbol{ .name = "ServiceObject" };/// The label `ReactorError`, which `reactorErrorRecord` writes.pub const SYM_REACTOR_ERROR = Symbol{ .name = "ReactorError" };/// The label `EntityRuntime`, which `entityRuntimeRecord` writes.pub const SYM_ENTITY_RUNTIME = Symbol{ .name = "EntityRuntime" };/// The label `ServiceDependency`, which `serviceDependencyRecord` writes.pub const SYM_SERVICE_DEPENDENCY = Symbol{ .name = "ServiceDependency" };/// The label `RestartService`, which `restartServiceRecord` writes.pub const SYM_RESTART_SERVICE = Symbol{ .name = "RestartService" };/// The symbol `null`, the value the package uses for JSON's null. `null_val` returns it, the JSON/// decoder makes it from JSON null, and `isNull` matches it.pub const SYM_NULL = Symbol{ .name = "null" };/// The symbol `_`, the wire form of the discard pattern, alone or as the record `<_>`./// `patternToPreserves` writes `<_>`, and `preservePattern` and `preservesToPattern` read both/// forms as the discard pattern.pub const SYM_DISCARD = Symbol{ .name = "_" };/// The label `bind` of the `<bind P>` record, the wire form of a capture. `patternToPreserves`/// writes it for captures and binds, and `preservePattern` and `preservesToPattern` read it as a/// capture.pub const SYM_BIND_PAT = Symbol{ .name = "bind" };/// The label `lit` of the `<lit v>` record, which matches the value `v` itself./// `patternToPreserves` writes it around atoms and sets, and `preservePattern` and/// `preservesToPattern` unwrap it.pub const SYM_LIT = Symbol{ .name = "lit" };/// The label `group` of the `<group type {…}>` record, the wire form of a record, sequence or/// dictionary pattern. `patternToPreserves` writes it, and `preservePattern` and/// `preservesToPattern` read it.pub const SYM_GROUP = Symbol{ .name = "group" };/// The label `rec` of `<rec L>`, the type of a group that matches records labeled `L`./// `patternToPreserves` writes it, and `preservePattern` and `preservesToPattern` read it.pub const SYM_REC = Symbol{ .name = "rec" };/// The label `arr` of `<arr>`, the type of a group that matches sequences. `patternToPreserves`/// writes it, and `preservePattern` and `preservesToPattern` read it.pub const SYM_ARR = Symbol{ .name = "arr" };/// The label `dict` of `<dict>`, the type of a group that matches dictionaries./// `patternToPreserves` writes it, and `preservePattern` and `preservesToPattern` read it.pub const SYM_DICT = Symbol{ .name = "dict" };test "Symbol equality and ordering" { const a = Symbol{ .name = "alpha" }; const b = Symbol{ .name = "alpha" }; const c = Symbol{ .name = "beta" }; try std.testing.expect(a.eql(b)); try std.testing.expect(!a.eql(c)); try std.testing.expectEqual(std.math.Order.lt, a.order(c)); try std.testing.expectEqual(std.math.Order.eq, a.order(b)); try std.testing.expectEqual(std.math.Order.gt, c.order(a));}test "well-known symbols match monolith constants" { try std.testing.expect(std.mem.eql(u8, SYM_OBSERVE.name, "Observe")); try std.testing.expect(std.mem.eql(u8, SYM_NULL.name, "null")); try std.testing.expect(std.mem.eql(u8, SYM_DISCARD.name, "_")); try std.testing.expect(std.mem.eql(u8, SYM_REC.name, "rec"));}Audit
| Definitions | 1 |
|---|---|
| Public names | 1 |
| Members | 0 |
| Version | 26.7.0 |
| Revision | daab053ee433 |