Under heavy development. This site describes the intended 1.0 language. Current features and performance vary. Development status
Sn50SnThe SnAPI programming language
Development · Evolving reference

TextFormatters

Appends an exact borrowed UTF-8 view without creating another owner.

Sn is under heavy development. This reference includes the intended 1.0 design; features may be incomplete in the current compiler. Read the status →

Module std.format

import std.format;

Public declaration contracts and authored examples. A page can document several related symbols. Implementation bodies are excluded.

fn

pub const fn FormatTo(
    Value: readonly str&,
    Builder: mut StringBuilder&
) -> void

Appends an exact borrowed UTF-8 view without creating another owner. Value: Borrowed UTF-8 view retained only for the call. Builder: Writable destination builder receiving bytes in source order. Return: No value; sticky allocation failure remains builder state.

Example

module example.text_formatting;
from std.format import FormatTo;
from std.text import String, StringBuilder;
fn Main() -> i32 {
    var Owned = switch String.TryCreate("owned") {
        case .Ok { Value = Value } => break Value;
        case .Err { Error = _ } => return 1;
    };
    let Prefix: str = "value=";
    let Suffix: char = '!';
    var Builder = StringBuilder();
    FormatTo(Prefix, Builder);
    FormatTo(Owned, Builder);
    FormatTo(Suffix, Builder);
    switch Builder.TryFinalize() {
        case .Ok { Value = Text } => {
            if Text.View != "value=owned!" { return 2; }
            return 0;
        }
        case .Err { Error = _ } => return 3;
    }
}

FormatTo

pub fn FormatTo(
    Value: readonly String&,
    Builder: mut StringBuilder&
) -> void

Appends bytes borrowed from one owning String without copying ownership. Value: Read-only owning String borrow valid for the call. Builder: Writable destination builder receiving bytes in source order. Return: No value; neither operation creates or transfers a String owner.

fn

pub const fn FormatTo(
    Value: readonly char&,
    Builder: mut StringBuilder&
) -> void

Appends one Unicode scalar in canonical UTF-8. Value: Borrowed scalar formatted exactly once. Builder: Writable destination builder receiving encoded bytes. Return: No value; sticky allocation failure remains builder state.

Documentation snapshot: October 24, 2026 About versions ↗
Searching Development · language & standard library