Skip to content

Commit 2d464a4

Browse files
committed
updated point, units
1 parent 20b454a commit 2d464a4

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

point.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ impl Point {
1010
}
1111

1212
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);
1617
}
1718

1819
fn flipped(&self) -> Point {
19-
Point{ x: self. y, y: self. x }
20+
Point{ x: self.y, y: self.x }
2021
}
2122

2223
fn collapse(self) -> i64 {
@@ -30,4 +31,4 @@ fn main() {
3031
p.flip();
3132
println!("{:?}", p);
3233
println!("{}", p.collapse());
33-
}
34+
}

units.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// https://doc.rust-lang.org/stable/rust-by-example/trait/derive.html
22

33
// A tuple struct that can be compared
4-
#[derive(PartialEq, PartialOrd)]
4+
#[derive(Debug, PartialEq, PartialOrd)]
55
struct Centimeters(f64);
66

77
// A tuple struct that can be printed
@@ -11,7 +11,6 @@ struct Inches(i32);
1111
impl Inches {
1212
fn to_centimeters(&self) -> Centimeters {
1313
let &Inches(inches) = self;
14-
1514
Centimeters(inches as f64 * 2.54)
1615
}
1716
}
@@ -32,18 +31,17 @@ fn main() {
3231
//let _this_is_true = _one_second == _one_second;
3332
// TODO ^ Try uncommenting this line
3433

35-
let foot = Inches(12);
34+
let yard = Inches(36);
3635

37-
println!("One foot === {:?}", foot);
36+
println!("One yard === {:?}", yard);
3837

3938
let meter = Centimeters(100.0);
4039

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+
};
4745

48-
println!("one foot is {} than one meter", cmp);
49-
}
46+
println!("one yard is {} than one meter", cmp);
47+
}

0 commit comments

Comments
 (0)