TextFormatters
Appends an exact borrowed UTF-8 view without creating another owner.
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&
) -> voidAppends 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&
) -> voidAppends 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&
) -> voidAppends 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.