1
- #[ derive( PartialEq , Debug , Clone ) ]
1
+ #[ derive( PartialEq , Debug , Copy , Clone ) ]
2
2
pub enum Direction {
3
3
North ,
4
4
East ,
@@ -26,6 +26,7 @@ impl Direction {
26
26
}
27
27
}
28
28
29
+ #[ derive( Clone , Copy ) ]
29
30
struct Position {
30
31
x : i32 ,
31
32
y : i32 ,
@@ -36,7 +37,7 @@ impl Position {
36
37
Position { x : x, y : y }
37
38
}
38
39
39
- fn advance ( self , direction : & Direction ) -> Self {
40
+ fn advance ( & self , direction : & Direction ) -> Self {
40
41
match direction {
41
42
& Direction :: North => Self :: new ( self . x , self . y + 1 ) ,
42
43
& Direction :: South => Self :: new ( self . x , self . y - 1 ) ,
@@ -63,19 +64,19 @@ impl Robot {
63
64
}
64
65
}
65
66
66
- pub fn turn_right ( self ) -> Self {
67
+ pub fn turn_right ( & self ) -> Self {
67
68
Self :: build ( self . position , self . direction . next_clockwise ( ) )
68
69
}
69
70
70
- pub fn turn_left ( self ) -> Self {
71
+ pub fn turn_left ( & self ) -> Self {
71
72
Self :: build ( self . position , self . direction . previous_clockwise ( ) )
72
73
}
73
74
74
- pub fn advance ( self ) -> Self {
75
+ pub fn advance ( & self ) -> Self {
75
76
Self :: build ( self . position . advance ( & self . direction ) , self . direction )
76
77
}
77
78
78
- pub fn instructions ( self , instructions : & str ) -> Self {
79
+ pub fn instructions ( & self , instructions : & str ) -> Self {
79
80
let mut r = Self :: build ( self . position , self . direction ) ;
80
81
for c in instructions. chars ( ) {
81
82
r = r. execute ( c) ;
0 commit comments