Mojo struct
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
- origins (
ImmutOrigin): The origin of the interpolated values. - format_string (
StringSlice): The compile-time format string template. - *Ts (
Writable): The types of the interpolated values.
Implemented traits
AnyType,
ImplicitlyDestructible,
Movable,
Writable
comptime members
__del__is_trivial
comptime __del__is_trivial = False
__move_ctor_is_trivial
comptime __move_ctor_is_trivial = True
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.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!