zlacker

[parent] [thread] 1 comments
1. sshine+(OP)[view] [source] 2024-01-23 13:53:50
> `Clone` is not zero cost, should we throw that out too?

Am I mistaken when I say that `ToOwned` is sometimes zero-cost?

And that `.to_owned()` vs. `.clone()` is free when the trait instances allow it?

replies(1): >>junon+Q5
2. junon+Q5[view] [source] 2024-01-23 14:23:38
>>sshine+(OP)
Both _can_ be free but are not inherently free.

For example, to_owned on an owned type is a no-op typically (it's a blanket implementation).

Clone on a unit struct or a unit enum variant is also a no-op in most cases (unless explicitly implemented not to be, which is very much frowned upon).

[go to top]