DEV Community

Discussion on: Pass-By-Value in C++ and Rust

Collapse
 
matsbror profile image
Mats Brorsson

I understand the ins-and-outs of C++ semantics and how it translates to machine code, but I still have some doubts about how it works in Rust. If I pass a reference in Rust, obviously it translates to an address being passed to the function.

However, if I pass an object that will move ownership to the function called, is this also an address? This is how the std::move would do it in C++ and it would make sense. Are any objects (or structs in Rust) ever passed in their entirety on the stack in Rust? There should be no need to, I think.

Collapse
 
deciduously profile image
Ben Lovy

I'm actually not positive and thus am hesitant to reply, but I think the semantics in Rust match std::move. I'll see if I can verify that and update you, though, don't make any life-critical decisions or anything based on that...