File tree Expand file tree Collapse file tree 1 file changed +4
-3
lines changed Expand file tree Collapse file tree 1 file changed +4
-3
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ struct State {
17
17
color : ( u8 , u8 , u8 ) ,
18
18
position : Point ,
19
19
quit : bool ,
20
+ message : String
20
21
}
21
22
22
23
impl State {
@@ -28,9 +29,7 @@ impl State {
28
29
self . quit = true ;
29
30
}
30
31
31
- fn echo ( & self , s : String ) {
32
- println ! ( "{}" , s) ;
33
- }
32
+ fn echo ( & mut self , s : String ) { self . message = s }
34
33
35
34
fn move_position ( & mut self , p : Point ) {
36
35
self . position = p;
@@ -52,6 +51,7 @@ mod tests {
52
51
quit : false ,
53
52
position : Point { x : 0 , y : 0 } ,
54
53
color : ( 0 , 0 , 0 ) ,
54
+ message : "hello world" . to_string ( ) ,
55
55
} ;
56
56
state. process ( Message :: ChangeColor ( 255 , 0 , 255 ) ) ;
57
57
state. process ( Message :: Echo ( String :: from ( "hello world" ) ) ) ;
@@ -62,5 +62,6 @@ mod tests {
62
62
assert_eq ! ( state. position. x, 10 ) ;
63
63
assert_eq ! ( state. position. y, 15 ) ;
64
64
assert_eq ! ( state. quit, true ) ;
65
+ assert_eq ! ( state. message, "hello world" ) ;
65
66
}
66
67
}
You can’t perform that action at this time.
0 commit comments