]> git.lizzy.rs Git - rust.git/blob - src/docs/mem_replace_option_with_none.txt
Auto merge of #9421 - xphoniex:fix-#9420, r=giraffate
[rust.git] / src / docs / mem_replace_option_with_none.txt
1 ### What it does
2 Checks for `mem::replace()` on an `Option` with
3 `None`.
4
5 ### Why is this bad?
6 `Option` already has the method `take()` for
7 taking its current value (Some(..) or None) and replacing it with
8 `None`.
9
10 ### Example
11 ```
12 use std::mem;
13
14 let mut an_option = Some(0);
15 let replaced = mem::replace(&mut an_option, None);
16 ```
17 Is better expressed with:
18 ```
19 let mut an_option = Some(0);
20 let taken = an_option.take();
21 ```