News for hackers. Stuff that matters.
Re:Beginner's guide to error handling in Rust by jcranmer on Sunday July 10, 2022 @02:25PM (#32047397)
> I would think the Err(err) => return Err(err) line needlessly constructs a copy of result.

You would think wrong. In Rust, everything is move by default. To create a copy, you need to explicitly call .clone() on an object (assuming it implements Clone, of course), or you can implement Copy for the type, which will cause .clone() to be called instead of moving the value.

(I'm not actually sure where the compiler will generate calls to clone() on Copy types in favor of moving. In practice, you're not going to implement Copy for a type that isn't trivially copyable anyways [using the C++ definition], so any optimizer would easily be able to elide any excessive copy operations.)

Re:Beginner's guide to error handling in Rust by joaonmatos on Sunday July 10, 2022 @04:10PM (#32048482)
Copy types must be trivially copiable bitwise (the clone implementation is returning the deref of the cloned type), so a copy is a move except for the fact that the previous reference is not invalidated.

The docs for the trait (core::marker::Copy) are pretty good