SplitScript reference / Display / toString
Display.toString
Method
Self.toString() -> String where Self: Display
Converts the receiver to its user-facing string representation.
A user struct 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
struct 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)
}