silk.schema.toml.
Read and write schema types as TOML.
When to use#
Use SchemaToml.decode for typed configuration files and SchemaToml.encode to write them.
The type's schema controls field names, defaults, validation, and unknown fields.
Details#
TOML tables become schema objects, and arrays become lists. Strings remain text without scalar coercion. Encoding writes root assignments and nested inline tables in declaration order, with bare keys where TOML allows them. Absent optional fields are omitted. TOML has no null value; a null inside an array cannot be encoded.
Import as SchemaToml with import silk.schema.toml { SchemaToml }.
Public declarations: 3.
SchemaToml#
pub struct SchemaTomlThe entry points for reading and writing schema types as TOML.
Implementation SchemaToml#
impl SchemaTomlAssociated function decode#
pub effect fn decode<T: Schema>(bytes: &[u8]) -> T
! SchemaError | OutOfMemoryError
? &mut AllocatorReads a typed TOML document, stopping at the first problem.
Errors#
SchemaErrorif TOML syntax or schema validation fails. The path identifies the failing field.OutOfMemoryErrorif the allocator cannot supply the document or value.
Associated function decodeAll#
pub effect fn decodeAll<T: Schema>(bytes: &[u8]) -> T
! SchemaErrors | OutOfMemoryError
? &mut AllocatorReads a typed TOML document and reports all schema problems, up to 64.
Details#
A field, element or variant that fails is recorded and skipped, and reading goes on with the
next one, so one call lists every problem, in schema order: a missing key, a wrong type, a
number out of range and a failed rule alike. Text that is not valid TOML is the one problem
reported. At most MAX_PROBLEMS (64) are listed.
Errors#
SchemaErrorswith every problem found.OutOfMemoryErrorif theAllocatorcannot supply the document or the value.
Associated function encode#
pub effect fn encode<T: Schema>(value: &T) -> ()
! SchemaError | WriterError | OutOfMemoryError
? &mut Writer | &mut AllocatorWrites a typed value as a TOML document, without flushing the writer.
Details#
The root must be an object. Nested objects use inline tables. Absent optional fields are omitted.
Errors#
SchemaErrorif the root is not an object, a list contains null, or nesting exceeds 64 levels.WriterErrorif output fails; already accepted bytes remain written.OutOfMemoryErrorif a custom codec cannot allocate.
TomlSchemaReader#
pub struct TomlSchemaReader<'document>A schema reader over a parsed TOML value. Semantic errors have field paths; syntax errors also have byte spans.
Implementation TomlSchemaReader<'document>#
impl<'document> TomlSchemaReader<'document>Associated function make#
pub fn make(value: &'document Value) -> SelfReturns a reader that stops at the first schema problem.
Associated function collectingAll#
pub fn collectingAll(value: &'document Value) -> SelfReturns a reader that collects up to 64 schema problems.
Method intoErrors#
pub fn intoErrors(self: Self) -> List<SchemaError>Returns the recorded schema problems in traversal order.
Implementation SchemaReader for TomlSchemaReader<'document>#
impl<'document> SchemaReader for TomlSchemaReader<'document>Operation path#
fn path(self: &mut Self) -> &mut SchemaPathOperation collecting#
fn collecting(self: &Self) -> boolOperation lastKind#
fn lastKind(self: &Self) -> ValueKindOperation report#
effect fn report(self: &mut Self, issue: Issue) -> ()
! Issue | OutOfMemoryError
? &mut AllocatorOperation mark#
effect fn mark(self: &mut Self) -> usize
! OutOfMemoryError
? &mut AllocatorOperation recover#
effect fn recover(self: &mut Self, mark: usize, skip: bool) -> ()
! Issue | OutOfMemoryError
? &mut AllocatorOperation release#
fn release(self: &mut Self, mark: usize) -> ()Operation boolean#
effect fn boolean(self: &mut Self) -> bool
! Issue | OutOfMemoryError
? &mut AllocatorOperation signed#
effect fn signed(self: &mut Self) -> i64
! Issue | OutOfMemoryError
? &mut AllocatorOperation unsigned#
effect fn unsigned(self: &mut Self) -> u64
! Issue | OutOfMemoryError
? &mut AllocatorOperation float#
effect fn float(self: &mut Self) -> f64
! Issue | OutOfMemoryError
? &mut AllocatorOperation text#
effect fn text(self: &mut Self) -> String
! Issue | OutOfMemoryError
? &mut AllocatorOperation null#
effect fn null(self: &mut Self) -> bool
! Issue | OutOfMemoryError
? &mut AllocatorOperation beginList#
effect fn beginList(self: &mut Self) -> ()
! Issue | OutOfMemoryError
? &mut AllocatorOperation nextElement#
effect fn nextElement(self: &mut Self) -> bool
! Issue | OutOfMemoryError
? &mut AllocatorOperation beginObject#
effect fn beginObject(self: &mut Self) -> ()
! Issue | OutOfMemoryError
? &mut AllocatorOperation member#
effect fn member(self: &mut Self, key: string) -> bool
! Issue | OutOfMemoryError
? &mut AllocatorOperation nextMember#
effect fn nextMember(self: &mut Self) -> Option<String>
! Issue | OutOfMemoryError ? &mut AllocatorOperation rejectUnread#
effect fn rejectUnread(self: &mut Self, expected: string<'static>) -> ()
! Issue | OutOfMemoryError
? &mut AllocatorOperation endObject#
effect fn endObject(self: &mut Self) -> ()
! Issue | OutOfMemoryError
? &mut AllocatorTomlSchemaWriter#
pub struct TomlSchemaWriterA SchemaWriter that writes TOML assignments and inline tables to the ambient Writer.
When to use#
SchemaToml.encode uses it. The root must be an object. Optional fields with no value are omitted by the schema.
Implementation TomlSchemaWriter#
impl TomlSchemaWriterAssociated function make#
pub fn make() -> TomlSchemaWriterReturns a writer for one top-level value.
Implementation SchemaWriter for TomlSchemaWriter#
impl SchemaWriter for TomlSchemaWriterOperation boolean#
effect fn boolean(self: &mut Self, value: bool) -> ()
! Issue | WriterError
? &mut WriterWrites true or false.
Operation signed#
effect fn signed(self: &mut Self, value: i64) -> ()
! Issue | WriterError
? &mut WriterWrites the integer in decimal.
Operation unsigned#
effect fn unsigned(self: &mut Self, value: u64) -> ()
! Issue | WriterError
? &mut WriterWrites the integer in decimal.
Operation float#
effect fn float(self: &mut Self, value: f64) -> ()
! Issue | WriterError
? &mut WriterWrites a TOML float, including infinities and NaN.
Operation text#
effect fn text(self: &mut Self, value: string) -> ()
! Issue | WriterError
? &mut WriterWrites a quoted TOML string.
Operation null#
effect fn null(self: &mut Self) -> ()
! Issue | WriterError
? &mut WriterRejects null, which TOML cannot represent.
Operation beginList#
effect fn beginList(self: &mut Self) -> ()
! Issue | WriterError
? &mut WriterWrites [.
Operation element#
effect fn element(self: &mut Self) -> ()
! Issue | WriterError
? &mut WriterWrites , before every element but the first.
Operation endList#
effect fn endList(self: &mut Self) -> ()
! Issue | WriterError
? &mut WriterWrites ].
Operation beginObject#
effect fn beginObject(self: &mut Self) -> ()
! Issue | WriterError
? &mut WriterStarts the root document or a nested inline table.
Operation key#
effect fn key(self: &mut Self, name: string) -> ()
! Issue | WriterError
? &mut WriterSeparates assignments and writes the key followed by =. A key of ASCII letters, digits, - and _ is written bare, any other key quoted.
Operation endObject#
effect fn endObject(self: &mut Self) -> ()
! Issue | WriterError
? &mut WriterEnds the root document or a nested inline table.
Category: Data formats.
Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, wasm32-wasip1, wasm32-wasip2, x86_64-pc-windows-msvc, wasm64-unknown-unknown.