I guess I could do this:
pub fn finalize(self) -> BufReadGuard<T> {
let mut this = std::mem::ManuallyDrop::new(self);
BufReadGuard::new(take(&mut this.buffer), this.recycler.clone())
}
But wouldn't this be even nicer?
pub fn finalize(self) -> BufReadGuard<T> {
let this = std::mem::ManuallyDrop::new(self);
BufReadGuard::new(this.buffer, this.recycler)
}
Unfortunately:
Compiling playground v0.0.1 (/playground)
error[E0507]: cannot move out of dereference of `ManuallyDrop<BufWriteGuard<T>>`
--> src/main.rs:54:27
|
54 | BufReadGuard::new(this.buffer, this.recycler)
| ^^^^^^^^^^^ move occurs because value has type `Vec<T>`, which does not implement the `Copy` trait
error[E0507]: cannot move out of dereference of `ManuallyDrop<BufWriteGuard<T>>`
--> src/main.rs:54:40
|
54 | BufReadGuard::new(this.buffer, this.recycler)
| ^^^^^^^^^^^^^ move occurs because value has type `UnboundedSender<Vec<T>>`, which does not implement the `Copy` trait
For more information about this error, try `rustc --explain E0507`.
error: could not compile `playground` due to 2 previous errors
I guess that's because ManuallyDrop
is an ordinary wrapper and not some sort of language-built-in feature.