@@ -9,28 +9,28 @@ pub struct Coord {
99}
1010
1111impl Coord {
12- pub const LEFT : Coord = Coord { x : -1 , y : 0 } ;
13- pub const RIGHT : Coord = Coord { x : 1 , y : 0 } ;
14- pub const UP : Coord = Coord { x : 0 , y : -1 } ;
15- pub const DOWN : Coord = Coord { x : 0 , y : 1 } ;
12+ pub const LEFT : Self = Self { x : -1 , y : 0 } ;
13+ pub const RIGHT : Self = Self { x : 1 , y : 0 } ;
14+ pub const UP : Self = Self { x : 0 , y : -1 } ;
15+ pub const DOWN : Self = Self { x : 0 , y : 1 } ;
1616}
1717
1818impl Coord {
1919 #[ must_use]
20- pub fn new ( x : i32 , y : i32 ) -> Self {
20+ pub const fn new ( x : i32 , y : i32 ) -> Self {
2121 Self { x, y }
2222 }
2323
2424 #[ must_use]
25- pub fn manhattan_distance ( & self , rhs : & Coord ) -> i32 {
25+ pub const fn manhattan_distance ( & self , rhs : & Self ) -> i32 {
2626 ( self . x - rhs. x ) . abs ( ) + ( self . y - rhs. y ) . abs ( )
2727 }
2828}
2929
3030impl Add for Coord {
31- type Output = Coord ;
32- fn add ( self , rhs : Coord ) -> Coord {
33- Coord {
31+ type Output = Self ;
32+ fn add ( self , rhs : Self ) -> Self {
33+ Self {
3434 x : self . x + rhs. x ,
3535 y : self . y + rhs. y ,
3636 }
@@ -45,9 +45,9 @@ impl AddAssign for Coord {
4545}
4646
4747impl Sub for Coord {
48- type Output = Coord ;
49- fn sub ( self , rhs : Coord ) -> Coord {
50- Coord {
48+ type Output = Self ;
49+ fn sub ( self , rhs : Self ) -> Self {
50+ Self {
5151 x : self . x - rhs. x ,
5252 y : self . y - rhs. y ,
5353 }
@@ -62,10 +62,10 @@ impl SubAssign for Coord {
6262}
6363
6464impl Mul < i32 > for Coord {
65- type Output = Coord ;
65+ type Output = Self ;
6666
67- fn mul ( self , rhs : i32 ) -> Coord {
68- Coord {
67+ fn mul ( self , rhs : i32 ) -> Self {
68+ Self {
6969 x : self . x * rhs,
7070 y : self . y * rhs,
7171 }
0 commit comments