Hacker News new | ask | show | jobs
by dirtydroog 2214 days ago
Oh my good god.

I'm hoping this is down to developer naivety rather than being a feature of rust.

3 comments

It's not a feature of Rust; it's a "feature" of the way we design operating systems and processors. This is the same in C.
The same could happen in C++, I think. Destructors are supposed to be called recursively.
1) he should pass by reference to avoid the extra copy. So in his example yes it’s dev naivety

2) but somewhere somehow this object will deallocate, so his trick of putting it to another thread would work if the deal location takes awhile. Same for cpp if you have a massive object in a unique ptr. So it’s not a rust issue

Where's the extra copy? I don't see one. He's moving the struct into the function, getting size and then dropping it.
> avoid the extra copy

there is no copy happening here