Rust traits have the neat property where you can use them either as generic bounds or as dynamic dispatch, with the &dyn MyTrait
syntax. The latter is necessary in heterogeneous scenarios, where you want to use multiple concrete types together that all implement a common trait. However, that requires that you have an instance, so that the reference actually “refers” to something. What if you have a trait with “static” requirements, like const
s or methods without &self
?
Type Erasure in Rust
Soft Orders of Magnitude
If there’s one safe thing to complain about for any software development process, it’s that build times are too long. It doesn’t matter if it’s a minute, five minutes, or a hour—it could always be shorter. No one’s going to argue with that, right?
There's No Such Thing As "Implicitly Atomic"
If I have an aligned machine-word-sized variable (Int) and I store to it from Thread A, then I know Thread B might see the old value instead of the new value (because of per-processor caching, or the compiler “hoisting” a load to earlier in the function). But there’s no way, on a modern processor, that Thread B sees a mix of the old and new value, right? That can only happen with wider values, or unaligned values, that the code may update non-atomically, right?
This question is paraphrased from the Swift forums, though I’m not linking to it cause it’s in the middle of a larger thread and it’s something people might reasonably ask anyway. My response, lightly edited, is below; it is Swift-oriented but also applies to C, C++, and Rust.