|
|
|
|
|
by kevincox
1248 days ago
|
|
For floats you do end up having to use `as` which is unfortunate. However the amount of things that can go wrong is too vast for `TryInto`. The article also says "If you upcast u32 to u64, you can use the keyword as". I would avoid this. In these cases you can just use `.into()`. This is infallible and will raise errors if refactoring causes that conversion to no longer be infallible. (In which case you can fix it or migrate to `.try_into()`) I think the floating point case is similar. Keep `as` super suspicious, but sometimes you do want to do it. |
|
The compiler can't even imagine what the code should look like, after all this type can't exist, does it fit in a register? How do we perform operations on it? If we try to actually realise an empty type by e.g. dereferencing a pointer to it that somebody gave us from a C API the Rust compiler will reject that as nonsense.