Examples · learn/05-structs · 108 of 339
nested
tin run examples/learn/05-structs/nested.tintype Point = { x: float, y: float }
type Line = { from: Point, to: Point }
fn length(l: Line): float {
let dx = l.to.x - l.from.x
let dy = l.to.y - l.from.y
sqrt(dx * dx + dy * dy)
}
fn main() {
let line = Line { from: Point { x: 0.0, y: 0.0 }, to: Point { x: 3.0, y: 4.0 } }
print(length(line))
}