summaryrefslogtreecommitdiff
path: root/lang/cairo/files/op_overloading.cairo
blob: 38637b90ae1b2cdba369127c2acdd0ca68f6003d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#[derive(PartialEq, Drop)]
struct Vector2 {
    x: felt252,
    y: felt252,
}

impl Vector2Add of Add<Vector2> {
    fn add(lhs: Vector2, rhs: Vector2) -> Vector2 {
            Vector2 { x: lhs.x + rhs.x, y: lhs.y + rhs.y }
        }
}

fn main() {
    let v = Vector2 { x: 1, y: 0 };
    let w = Vector2 { x: 0, y: 1 };
    
    assert(v + w == Vector2 { x: 1, y: 1 }, 'Should be equal.')
}