2 ms·
It monomorphizes generic functions and methods. Type erasure happens to the actual values. So, for example, at run time an Option<i32> ends up just storing one
by mumblemumble 5y ago
It monomorphizes generic functions and methods. Type erasure happens to the actual values.
So, for example, at run time an Option<i32> ends up just storing one word for indicating whether it's Some or None, and another for the value when it's Some, but doesn't store any information to indicate that those 8 bytes represent an Option<T> of any kind, let alone exactly what kind of value is being stored in it. None of that is needed at run time, because the compiler was able to statically verify that no function is going to try to read them as a u64 instead.
- jcelerier 5y agoI have never heard such a definition of type erasure, generally it means that the concrete type is hidden behind a generic "OO" interface which is itself hidden behind a value type providing the same interface / API