Under heavy development. This site describes the intended 1.0 language. Current features and performance vary. Development status
Sn50SnThe SnAPI programming language
0.2.0 Preview 1 · Frozen documentation

PrimitiveFormatters

Appends canonical lowercase `true` or `false` bytes.

Sn is under heavy development. Reference extracted from this release’s bundled standard library. Public API examples are not an exhaustive compatibility test. Read the matching release guide for tested workflows and limitations. 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 bool&, Builder: mut StringBuilder&) -> void;

Appends canonical lowercase true or false bytes. Value: Borrowed Boolean value formatted exactly once. Builder: Writable destination builder borrow. Return: No value; sticky allocation failure remains private builder state.

Example

module example.primitive_formatting;
from std.format import FormatTo;
from std.text import StringBuilder;
const Flag: bool = true;
const Signed: i32 = 7;
const Octet: byte = 8;
const Size: usize = 9;
const Offset: isize = 10;
fn Main() -> i32 {
    var Builder = StringBuilder();
    FormatTo(Flag, Builder);
    Builder.Append(' ');
    FormatTo(Signed, Builder);
    Builder.Append(' ');
    FormatTo(Octet, Builder);
    Builder.Append(' ');
    FormatTo(Size, Builder);
    Builder.Append(' ');
    FormatTo(Offset, Builder);
    switch Builder.TryFinalize() {
        case .Ok { Value = Text } => {
            if Text.View != "true 7 8 9 10" { return 1; }
            return 0;
        }
        case .Err { Error = _ } => return 2;
    }
}

fn

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

Appends minimal decimal i32 bytes with a minus only for negative values. Value: Borrowed signed value formatted exactly once. Builder: Writable destination builder borrow. Return: No value; sticky allocation failure remains private builder state.

fn

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

Appends minimal unsigned decimal byte bytes. Value: Borrowed byte value formatted exactly once. Builder: Writable destination builder borrow. Return: No value; sticky allocation failure remains private builder state.

fn

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

Appends target-width minimal unsigned decimal usize bytes. Value: Borrowed target-width unsigned value formatted exactly once. Builder: Writable destination builder borrow. Return: No value; sticky allocation failure remains private builder state.

fn

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

Appends target-width minimal signed decimal isize bytes. Value: Borrowed target-width signed value formatted exactly once. Builder: Writable destination builder borrow. Return: No value; sticky allocation failure remains private builder state.

fn

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

Appends exact minimal decimal i8 text without intermediate allocation. Value: Borrowed integer; its full range is preserved. Builder: Writable destination; sticky allocation failure is retained. Return: No value; TryFinalize reports destination allocation failures.

Example

module example.extended_integer_formatting;
from std.format import FormatTo;
from std.text import StringBuilder;
fn Main() -> i32 {
    var Builder = StringBuilder();
    FormatTo(-128_i8, Builder);
    Builder.Append(' ');
    FormatTo(-32768_i16, Builder);
    Builder.Append(' ');
    FormatTo(-9223372036854775808_i64, Builder);
    Builder.Append(' ');
    FormatTo(-170141183460469231731687303715884105728_i128, Builder);
    Builder.Append(' ');
    FormatTo(255_u8, Builder);
    Builder.Append(' ');
    FormatTo(65535_u16, Builder);
    Builder.Append(' ');
    FormatTo(4294967295_u32, Builder);
    Builder.Append(' ');
    FormatTo(18446744073709551615_u64, Builder);
    Builder.Append(' ');
    FormatTo(340282366920938463463374607431768211455_u128, Builder);
    switch Builder.TryFinalize() {
        case .Ok { Value = Text } => {
            if Text.View != "-128 -32768 -9223372036854775808 -170141183460469231731687303715884105728 255 65535 4294967295 18446744073709551615 340282366920938463463374607431768211455" { return 1; }
            return 0;
        }
        case .Err { Error = _ } => return 2;
    }
}

fn

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

Appends exact minimal decimal i16 text without intermediate allocation. Value: Borrowed integer; its full range is preserved. Builder: Writable destination; sticky allocation failure is retained. Return: No value; TryFinalize reports destination allocation failures.

fn

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

Appends exact minimal decimal i64 text without intermediate allocation. Value: Borrowed integer; its full range is preserved. Builder: Writable destination; sticky allocation failure is retained. Return: No value; TryFinalize reports destination allocation failures.

fn

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

Appends exact minimal decimal i128 text without intermediate allocation. Value: Borrowed integer; its full range is preserved. Builder: Writable destination; sticky allocation failure is retained. Return: No value; TryFinalize reports destination allocation failures.

fn

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

Appends exact minimal decimal u8 text without intermediate allocation. Value: Borrowed integer; its full range is preserved. Builder: Writable destination; sticky allocation failure is retained. Return: No value; TryFinalize reports destination allocation failures.

fn

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

Appends exact minimal decimal u16 text without intermediate allocation. Value: Borrowed integer; its full range is preserved. Builder: Writable destination; sticky allocation failure is retained. Return: No value; TryFinalize reports destination allocation failures.

fn

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

Appends exact minimal decimal u32 text without intermediate allocation. Value: Borrowed integer; its full range is preserved. Builder: Writable destination; sticky allocation failure is retained. Return: No value; TryFinalize reports destination allocation failures.

fn

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

Appends exact minimal decimal u64 text without intermediate allocation. Value: Borrowed integer; its full range is preserved. Builder: Writable destination; sticky allocation failure is retained. Return: No value; TryFinalize reports destination allocation failures.

fn

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

Appends exact minimal decimal u128 text without intermediate allocation. Value: Borrowed integer; its full range is preserved. Builder: Writable destination; sticky allocation failure is retained. Return: No value; TryFinalize reports destination allocation failures.

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