On a side note, here is a playground showing that in fact you cannot impl both Copy
and Drop
on a type.
1 Like
Why would you want to pass by ref in those cases, though? I'd much rather call foo(0)
than foo(&0)
...
Sorry, I meant to say:
In the situation where an object:
- has an O(1) Clone
- does NOT have Copy
then just pass it by Ref (and have the called function do the clone).
If an object has Copy, just pass it by value, as you have suggested.
So now we're at the point where the rules are
- If the type is
!Clone
, pass an owned value if the function needs an owned value - If the type has an expensive
Clone
, pass an owned value if the function needs an owned value - If the type has a refcount, pass an owned value if the function needs an owned value
- If the type is
Copy
, pass an owned value if the function needs an owned value
So I really think the rule for the small set of remaining types (I can't even think of one offhand) should also be "pass an owned value if the function needs an owned value", because that would make it way easier to write the rule down
1 Like
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.