rust-unofficial / patterns

A catalogue of Rust design patterns, anti-patterns and idioms
https://rust-unofficial.github.io/patterns/
Mozilla Public License 2.0
7.98k stars 363 forks source link

mem-take instead of mem-replace #96

Closed jeffcutsinger closed 3 years ago

jeffcutsinger commented 4 years ago

In https://github.com/rust-unofficial/patterns/blob/964dd9932b7bf41b0905c264ea065781efcdb6b7/idioms/mem-replace.md,

mem::replace(name, String::new())

can be made more terse by using

mem::take(name)

instead. Rust playground link to show it still compiles: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=6f29fd3165760bf068a7c4200fa8cbc5

pickfire commented 4 years ago

Interested to send a patch for this?