silk.toml.format.
Format TOML documents without changing comments, value spellings, or declaration order.
When to use#
Use TomlFormat before saving edited TOML text. Use silk.toml.output to serialize a value tree.
Import as TomlFormat with import silk.toml.format { TomlFormat }.
Public declarations: 1.
TomlFormat#
pub struct TomlFormatA comment-preserving TOML formatter with two-space indentation for nested values.
Implementation TomlFormat#
impl TomlFormatAssociated function format#
pub effect fn format(source: string) -> String
! TomlError | OutOfMemoryError
? &mut AllocatorReturns formatted TOML text, preserving comments, literal spellings, and declaration order.
Details#
Spaces surround = and follow commas. Inline tables have spaces inside their braces.
Nested values use two-space indentation. Existing line breaks inside arrays and inline tables remain.
Dotted keys have no spaces around dots. Blank runs become one blank line, and nonempty output ends with LF.
String contents remain byte-for-byte unchanged, including embedded line endings. Other line endings become LF.
Repeated formatting returns the same text. Empty or whitespace-only input produces an empty string.
Errors#
TomlErrorif the input is invalid TOML, including duplicate keys and conflicting tables.OutOfMemoryErrorif validation or output allocation fails. The input remains unchanged.
Associated function formatBytes#
pub effect fn formatBytes(source: &[u8]) -> Bytes
! TomlError | OutOfMemoryError
? &mut AllocatorReturns formatted TOML file bytes, preserving comments, literal spellings, and declaration order.
Details#
Spaces surround = and follow commas; inline tables have spaces inside braces.
Nested values use two-space indentation. Existing array and inline-table line breaks remain.
Dotted keys have no spaces around dots. Blank runs become one blank line; nonempty output ends with LF.
String contents remain byte-for-byte unchanged. Other line endings become LF.
Repeated formatting returns the same bytes. Empty or whitespace-only input produces empty output.
Errors#
TomlErrorif the bytes are invalid UTF-8 or invalid TOML, including duplicate keys and conflicting tables.OutOfMemoryErrorif validation or output allocation fails. The input remains unchanged.
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.