Skip to content

Commit 547ff18

Browse files
committed
Adressed comments
1 parent 31b282a commit 547ff18

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ language.
2222
* [Iterating over an `Option`](idioms/option-iter.md)
2323
* TODO `Default` trait
2424
* [Pass variables to closure](idioms/pass-var-to-closure.md)
25+
* [`mem::replace(_)` to avoid needless clones](idioms/mem-replace.md)
2526

2627
### Design patterns
2728

idioms/mem-replace.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn a_to_b(e: &mut MyEnum) {
1919
// we could just take a reference to `name` and clone that, but why pay an
2020
// extra allocation for something we already have?
2121
let have_name = match *e {
22-
MyEnum::A(ref mut name, x) if x == 0 => {
22+
MyEnum::A { ref mut name, x } if x == 0 => {
2323
// this takes out our `name` and put in an empty String instead
2424
// note that empty strings don't allocate
2525
Some(mem::replace(name, "".to_string()))
@@ -28,7 +28,7 @@ fn a_to_b(e: &mut MyEnum) {
2828
_ => None
2929
};
3030
// the mutable borrow ends here, so we can change `e`
31-
if let Some(name) = have_name { *e = MyEnum::B { name } }
31+
if let Some(name) = have_name { *e = MyEnum::B { name: name } }
3232
}
3333
```
3434

@@ -80,4 +80,4 @@ like Indiana Jones, replacing the artifact with a bag of sand.
8080
This gets rid of the [Clone to satisfy the borrow checker] antipattern in a
8181
specific case.
8282

83-
[Clone to satisfy the borrow checker]()
83+
[Clone to satisfy the borrow checker](TODO: Hinges on PR #23)

0 commit comments

Comments
 (0)