File tree Expand file tree Collapse file tree 2 files changed +16
-17
lines changed Expand file tree Collapse file tree 2 files changed +16
-17
lines changed Original file line number Diff line number Diff line change @@ -10,13 +10,14 @@ impl Point {
10
10
}
11
11
12
12
fn flip ( & mut self ) {
13
- let tmp = self . x ;
14
- self . x = self . y ;
15
- self . y = tmp;
13
+ // let tmp = self.x;
14
+ // self.x = self.y;
15
+ // self.y = tmp;
16
+ std:: mem:: swap ( & mut self . x , & mut self . y ) ;
16
17
}
17
18
18
19
fn flipped ( & self ) -> Point {
19
- Point { x : self . y , y : self . x }
20
+ Point { x : self . y , y : self . x }
20
21
}
21
22
22
23
fn collapse ( self ) -> i64 {
@@ -30,4 +31,4 @@ fn main() {
30
31
p. flip ( ) ;
31
32
println ! ( "{:?}" , p) ;
32
33
println ! ( "{}" , p. collapse( ) ) ;
33
- }
34
+ }
Original file line number Diff line number Diff line change 1
1
// https://doc.rust-lang.org/stable/rust-by-example/trait/derive.html
2
2
3
3
// A tuple struct that can be compared
4
- #[ derive( PartialEq , PartialOrd ) ]
4
+ #[ derive( Debug , PartialEq , PartialOrd ) ]
5
5
struct Centimeters ( f64 ) ;
6
6
7
7
// A tuple struct that can be printed
@@ -11,7 +11,6 @@ struct Inches(i32);
11
11
impl Inches {
12
12
fn to_centimeters ( & self ) -> Centimeters {
13
13
let & Inches ( inches) = self ;
14
-
15
14
Centimeters ( inches as f64 * 2.54 )
16
15
}
17
16
}
@@ -32,18 +31,17 @@ fn main() {
32
31
//let _this_is_true = _one_second == _one_second;
33
32
// TODO ^ Try uncommenting this line
34
33
35
- let foot = Inches ( 12 ) ;
34
+ let yard = Inches ( 36 ) ;
36
35
37
- println ! ( "One foot === {:?}" , foot ) ;
36
+ println ! ( "One yard === {:?}" , yard ) ;
38
37
39
38
let meter = Centimeters ( 100.0 ) ;
40
39
41
- let cmp =
42
- if foot. to_centimeters ( ) < meter {
43
- "smaller"
44
- } else {
45
- "bigger"
46
- } ;
40
+ let cmp = if yard. to_centimeters ( ) < meter {
41
+ "smaller"
42
+ } else {
43
+ "bigger"
44
+ } ;
47
45
48
- println ! ( "one foot is {} than one meter" , cmp) ;
49
- }
46
+ println ! ( "one yard is {} than one meter" , cmp) ;
47
+ }
You can’t perform that action at this time.
0 commit comments