Я пытаюсь написать 2 структуры Point
и Bound
, чтобы вы могли вычесть Point
из Bound
.
Код:
struct Point {
x:usize,
y:usize,
}
impl Sub for Point {
type Output = Point;
fn sub(self,other:Point) -> Point {
Point { x:self.x-other.x, y:self.y-other.y }
}
}
struct Bound { min:Point,max:Point }
impl Sub for Bound {
type Output = Bound;
fn sub(self,other:Point) -> Bound {
Bound { min:self.min-other, max:self.max-other }
}
}
Я получаю сообщение об ошибке:
method `sub` has an incompatible type for trait
expected struct `construct::Bound`, found struct `construct::Point`
note: expected fn pointer `fn(construct::Bound, construct::Bound) -> construct::Bound`
found fn pointer `fn(construct::Bound, construct::Point) -> construct::Bound`rustc(E0053)
main.rs(565, 9): expected struct `construct::Bound`, found struct `construct::Point`
Возможен ли способ, которым я здесь пытаюсь? Как лучше всего это сделать?