IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /docs/manual/basics.md). For the complete Mojo documentation index, see llms.txt.
Skip to main content
Version: 1.0
For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).

TString

struct TString[origins: ImmutOrigin, //, format_string: StringSlice[StaticConstantOrigin], *Ts: Writable]

A template string that captures interpolated values at compile-time.

TString is a zero-cost abstraction for string interpolation that preserves type information and defers formatting until explicitly requested. Unlike regular strings or f-strings, TString retains the original format template and typed values, enabling efficient lazy formatting and type-safe string composition.

TString instances are created by the compiler when using t-string literal syntax: t"Hello {name}!".

Parameters

Implemented traits

AnyType, ImplicitlyDestructible, Movable, Writable

Methods

write_to

write_to(self, mut writer: T)

Write the formatted string to a writer.

This method implements the Writable trait by formatting the TString's template with its interpolated values and writing the result to the provided writer. The format string is compiled at compile-time for optimal performance.

Args:

  • writer (T): The writer to output the formatted string to.

write_repr_to

write_repr_to(self, mut writer: T)

Write a debug representation of the TString to a writer.

This method provides a detailed view of the TString's internal structure, showing the format template, type parameters, and the actual interpolated values. This is useful for debugging and understanding the TString's composition.

Args:

  • writer (T): The writer to output the debug representation to.