Avatar ·

Como implementar o trait Add para uma referência a uma struct em Rust?

Olá! Estou estudando Rust e tentando sobrecarregar o operador `+` para minha struct. Tenho uma struct `Point` com dois campos `x` e `y`. Quero poder somar duas instâncias de `Point` passando-as por referência, para não mover a posse. Aqui está meu código: ```rust struct Point { x: i32, y: i32, } impl std::ops::Add for Point { type Output = Point; fn add(self, other: Point) -> Point { Point { x: self.x + other.x, y: self.y + other.y } } } ``` Isso funciona, mas consome `self` e `other` por valor. Quero fazer de forma que possa escrever: ```rust let a = Point { x: 1, y: 2 }; let b = Point { x: 3, y: 4 }; let c = &a + &b; ``` Tentei escrever assim: ```rust impl std::ops::Add for &Point { type Output = Point; fn add(self, other: &Point) -> Point { Point { x: self.x + other.x, y: self.y + other.y } } } ``` Mas o compilador reclama sobre o tempo de vida (lifetime). O erro é mais ou menos: `mis