//! returns: 0 //! Multiple methods on the same type. record Vec2 { x: i32, y: i32, } fn (v: *Vec2) magnitudeSq() -> i32 { return v.x * v.x + v.y * v.y; } fn (v: *Vec2) dot(other: *Vec2) -> i32 { return v.x * other.x + v.y * other.y; } fn (v: *mut Vec2) add(other: *Vec2) { set v.x = v.x + other.x; set v.y = v.y + other.y; } fn (v: *mut Vec2) scale(factor: i32) { set v.x = v.x * factor; set v.y = v.y * factor; } @default fn main() -> i32 { let mut a = Vec2 { x: 3, y: 4 }; let b = Vec2 { x: 1, y: 2 }; // Immutable method. assert a.magnitudeSq() == 25; // Method with pointer parameter. assert a.dot(&b) == 11; // Mutable method with pointer parameter. a.add(&b); assert a.x == 4; assert a.y == 6; // Mutable method with scalar parameter. a.scale(2); assert a.x == 8; assert a.y == 12; return 0; }