Showing posts with label rust_trait. Show all posts
Showing posts with label rust_trait. Show all posts

Mar 15, 2023

[Rust] Drop trait and Copy trait are mutually exclusive

 


While if the user declared destructor in C++ the move constructor is by default not declared due to preventing double deletion after move if move constructor did not nullptr any data members that were heap allocated.

Same idea in Rust. With type implement Drop trait cannot implement Copy trait due to RAII triggers double deletion.

Take Vec<T,A>::Drop for example: source