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


No comments:

Post a Comment

Note: Only a member of this blog may post a comment.