Sub
trait Sub<T>
Source: compiler/src/builtin_docs/prelude/ops.hy The subtraction operator -.
a - b on a type with a Sub instance calls sub(a, b). int and
float have builtin instances.
Required methods#
| Name | Description |
|---|---|
sub | Returns a - b. |
Examples#
use tests::assert;
class V2 {
pub x: int,
pub y: int,
}
impl Sub for V2 {
pub fn sub(V2 a, V2 b) -> V2 {
return new V2(a.x - b.x, a.y - b.y);
}
}
fn main() {
let d = new V2(5, 5) - new V2(1, 2);
assert!(d.x == 4);
assert!(d.y == 3);
}