4 ms·
> If my 4K structure can be copied, should it derive `Copy`? This leads to users implicitly copying it around instead of using references more aggressively. Ru
by volta83 5y ago
> If my 4K structure can be copied, should it derive `Copy`? This leads to users implicitly copying it around instead of using references more aggressively.
Rust eliminates unnecessary memcpys, but this is a bit up to you. `Copy` as a synonym of "cheap to copy" is used by some crates, although this is not official AFAIK.
> If all my types implement `PartialEq`, `Debug`, and other stuff, that means a lot of code generation at compile time,
If you don't use these, no LLVM-IR is even generated for these. Rust compiles code "on demand".
- kvark 5y agoThen you are at mercy of Rust optimizer. I don't want to always think about Rust optimizer when looking at or reviewing the code. I want to see the costs explicitly in the code. Once Copy/Debug/PartialEq are derived, it will be tempting to use them, so the compile time cost will apply.
- tialaramex 5y agoThis is an API guide. So what you're talking about is deliberately making libraries you provide worse so that people aren't tempted to use them, that ought to be ringing some alarm bells.
- volta83 5y agoThese are guidelines that the standard library aims to follow. It does not blindly follow them, and they only represent the values and trade-offs that make sense for the standard library. If your projects have different values and trade-offs, just do your own thing (Rust's makes it easier than all other languages I know). If you don't want to use a standard library that follows these, just fork it and change it. Rust makes this trivial, and projects that must do this go and just do it. I really don't know what point you are trying to make. Implementing Copy for all types that are cheap to copy makes sense for most Rust programmers. That does not mean that it makes sense for _you_, but if you disagree about this not making sense for most, then Rust is probably the wrong language for you, and you should consider using something else.