There is no copy: https://rust.godbolt.org/z/6b8j51 It gets inlined and passing arguments doesn't cost anything.
Rust bets on zero-cost abstractions, so often function interfaces are chosen by their desired semantics, not performance, because the performance difference is abstracted away anyway.
But even if this function wasn't inlined, and for some reason it had to be executed very literally like in a compiler without a modern optimizer, it would still be more expensive to use a pointer:
- 64-bit pointers are 8 bytes themselves, so you still "copy" 8 bytes to the function.
- To have a pointer you'd have to have the data in memory. If the bytes were already in a register, they'd have to be written to memory first!
- Then the function would have to dereference the pointer, and copy the data out to the return register
So naively passing data by reference would copy 2-3 times more data. But Rust isn't designed to work with naive non-optimizing compilers, so keep in mind code actually doesn't do what functions signature suggest. Copy types aren't always copied. Reference types don't always exist as a reference either.