Interface Implementation
extend attaches methods to a type, optionally satisfying one or more interfaces.
rux
struct Circle {
radius: float64;
}
extend Circle {
func Area(self) -> float64 {
return Pi * self.radius * self.radius;
}
}
extend Circle: Display {
func ToString(self) -> String {
return Format("Circle: radius = {}", self.radius);
}
}The compiler verifies that the extend block provides every method the interface declares, with matching signatures. A type may satisfy any number of interfaces.
Once implemented, interface methods are called like any other method:
rux
let c = Circle { radius: 2.0 };
Print(c.ToString()); // Circle: radius = 2See Also
- Interface Declaration — the signatures an
extendblock must satisfy - Methods — the
extendblock and method syntax - Structures — the types being extended