SplitScript reference / Display / toString
Display.toString
Method
T.toString() -> String where T: Display
Converts the receiver to its user-facing string representation.
A user record or enum falls back to its derived Debug representation when this method is absent. Defining a method with this signature overrides that fallback. The String result may be inferred from the body, and no separate implementation declaration or annotation is needed. Display.toString powers as String casts, interpolation, print, and setVariable.
Effects: pure
Runtime behavior: available everywhere; synchronous
Examples
Display a user-defined position
record Position {
x: i32,
y: i32,
}
fn Position.toString() -> String {
return `({self.x}, {self.y})`
}
state "game.exe" {}
onAttach {
let positionText = Position { x: 3, y: 5 } as String
print(positionText)
}