Re:My favorite Rust function
by millstone on Saturday October 12, 2019 @09:09PM
(#21237546)
[ Parent
| on HN ]
FWIW, that won't compile because std::mem::drop requires ownership of the object being passed; your code is trying to pass a reference instead.
This code compiles just fine. It doesn't do anything since immutable references are Copy, and so dropping them doesn't do anything.
https://play.rust-lang.org/?version=stable&mode=debug&editio...
Oh right, I forgot about the interaction with generics in this case. Semantically, I suppose it's creating and dropping a reference 4 times.
Re:My favorite Rust function
by steveklabnik on Saturday October 12, 2019 @10:27PM
(#21237893)
This should compile, &T is Copy and so it will not really do anything, but it will still compile.
On my phone so I can’t triple check, but there’s no bound on T, you can pass in any type.