I have two related questions inspired by a
SetU64 that I'm developing for the next generation of tinyset. They regard the API for methods like
remove). The standard sets take [Borrow
](https://doc.rust-lang.org/std/collections/struct.HashSet.html#method.contains), since the code needs to work for "big" types like strings that you don't want to clone. For a small Copy
type likeu64` it feels like a wasteful complication to take references as input rather than just accepting the value you're looking for.
So my two questions are:
Which API would you prefer as the user of a set crate?
So you know if there could be a performance cost to accepting a reference rather than a value?
For the first question, the advantage of accepting a reference is that it allows to easily switch between container types. The advantage of accepting values is that if you aren't switching containers it's a bit more direct and intuitive (to me, anyhow). And if there is a performance advantage (see question 2), then that would be a reason not to use references.
For the performance question, naively one would expect that passing values would be cheaper than passing references, because they could be held in registers and the came would never have to be placed in slow RAM. However, I could also imagine that the compiler would recognize that it's easier and cheaper to pass a value than a reference and make that optimization. Does anyone know if it does this, or should be relied on to do so?