baml.ToString
Human-readable string conversion with an implicit structural default.
Reference version
Signature
interface baml.ToStringHuman-readable string conversion with an implicit structural default.
A type implements baml.ToString to control how string.from(value)
renders it. Conversion is total — to_string never throws.
class Point {
x int
y int
implements baml.ToString {
function to_string(self) -> string throws never {
"(" + string.from(self.x) + ", " + string.from(self.y) + ")"
}
}
}
Every type has an implicit implementation. An explicit implementation
overrides the structural rendering (see [_to_string_default]).
to_string carries that same structural rendering as its default body, so
implements baml.ToString {} with no override is valid and renders exactly
like a non-implementor.
Source:<builtin>/baml/conversions.bamlbytes 808–928
Default instance methods
function
to_string
(self) -> string throws neverRelated definitions
baml.errors.Contextbaml.errors.StackTracebaml.errors.UnknownErrorbaml.Stringbaml.time.Instantbaml.time.PlainDatebaml.time.PlainDateTimebaml.time.PlainTimebaml.time.ZonedDateTimebaml.Uint8Arraybaml.errors.Contextbaml.errors.StackTracebaml.errors.UnknownErrorbaml.time.Instantbaml.time.PlainDatebaml.time.PlainDateTimebaml.time.PlainTimebaml.time.ZonedDateTimebaml.Uint8Array