Wrapper to make any clonable structure also copyable?

I kind-of mentioned it, but without naming the traits explicitly.

Note that your phrasing is a bit inaccurate, too. A type implementing Copy does not only preclude that type implementing Drop, but it must also not have any other “drop glue” either, so all of its fields — transitively – can't implement Drop, too.


Don't rely on feelings, then. Even experienced programmers can be (and are often) wrong about what is and is not "optimal" or "efficient".

Does the above code cause a noticeable bottleneck in your application? No? Then don't worry about it.

If, and only if, it does, then do two things:

  • Look at the generated assembly. Don't speculate – compilers and optimizers are complex beasts, and there's a very low chance you will be able to correctly guess what the optimized output looks like unless you actually compile the code and look at the assembly.
  • Measure the timing in a statistically sound way. There are crates like Criterion that make this task painless. Don't run away yak-shaving and optimizing something that doesn't matter – thrive for pinpointing the real performance problems in your code instead.

Thank you.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.