3 ms·
That is a common misconception. The destructor runs at the end of the scope. Try putting a println in a drop impl.
by NieDzejkob 5y ago
That is a common misconception. The destructor runs at the end of the scope. Try putting a println in a drop impl.
- tialaramex 5y agoIf you do this with C++ destructors, they will sure enough fire at the end of the scope. Even if your String is long gone, the destructor fires anyway, destroying... a hollowed out String left behind to satisfy the destructor. But go ahead and try it in Rust, your print doesn't happen because nothing was actually dropped. The String was moved, and so there isn't anything to drop. https://gist.github.com/rust-play/4bbcc2a4efb641e578e84a1962b14903 https://gist.github.com/rust-play/4bbcc2a4efb641e578e84a1962...