]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #61130 - jonhoo:mem-take, r=SimonSapin
authorbors <bors@rust-lang.org>
Fri, 7 Jun 2019 18:26:15 +0000 (18:26 +0000)
committerbors <bors@rust-lang.org>
Fri, 7 Jun 2019 18:26:15 +0000 (18:26 +0000)
Add std::mem::take as suggested in #61129

This PR implements #61129 by adding `std::mem::take`.

The added function is equivalent to:
```rust
std::mem::replace(dest, Default::default())
```

This particular pattern is fairly common, especially when implementing `Future::poll`, where you often need to yield an owned value in `Async::Ready`. This change allows you to write
```rust
return Async::Ready(std::mem::take(self.result));
```
instead of
```rust
return Async::Ready(std::mem::replace(self.result, Vec::new()));
```

EDIT: Changed name from `take` to `swap_default`.
EDIT: Changed name back to `take`.

1  2 
src/libcore/mem/mod.rs

Simple merge