Recently, yesterday, I discovered that you can use pub use mod_name to re-export a module hiding part of the original path. This is very useful for re-exporting specific modules under the same name, for example you can create a module unix :: file and another one windows :: file and re-export as file without having to create an abstraction to access specific platform versions:
# [cfg (target_family = "unix")]
pub use unix :: file;
# [cfg (target_family = "windows")]
pub use windows :: file;
If you know other useful secrets like that, tell me.
That's from the cargo flamegraph README, written by a guy who I'm pretty sure is like a Rust performance expert and who writes a ridiculously fast Rust database:
I remember boxed array initialization to not be compiled away. I actually don't know, if Box::newever manages to initialize something directly on the heap, TBH. Does someone know?
I agree with the other points, tho. I'd also add, that sometimes, you just have to sprinkle a bit of #[inline] to help the optimizer compile away some otherwise expensive operations, if it fails to inline, before resorting to refactoring algorithms.
Also worth knowing about the anyhow fork eyre which has a cool library for fancy printing your errors: color_eyre. Anyhow or Eyre are both great, but if you want fancy printing, Eyre is probably better for that.