r/ProgrammerHumor • • Oct 10 '26

Meme theyAreLovingIt

Post image
2.1k Upvotes

83 comments sorted by

View all comments

Show parent comment

1

u/WriterPlastic9350 Oct 10 '26

Pass-By-Move is the default in Rust. Pass by move makes no damn sense for a simple struct of {X, Y, Z} coordinates. [..] Seems sus to make it the default

Well, for one, pass-by-reference requires a deference. Pass-by-move also matches the ownership model in Rust.

Just because Rust uses that ownership model does not mean it will actually use std::move for every function call. Rust's compiler is able to make assumptions based on the fact that things are generally immutable and copied rather than aliased that can eliminate most actual moves or copies unless it cannot prove that the function doesn't modify the value

1

u/Hohenheim_of_Shadow Oct 11 '26

Pass by Copy is the alternative and is the sensible default for simple stack based structs.

For purely stack based data types, Pass by Move is Pass by Copy with the gotcha of invalidating the original variable. Of immutability is the goal, Pass by Move is far worse than Copy for simple stack structs.