Closed
Description
If you try to compile the code (play link):
vec![0.0].iter().map(|s| s as i16).collect::<Vec<i16>>();
You get the error
rustc 1.14.0-nightly (6e8f92f11 2016-10-07)
error: casting `&f64` as `i16` is invalid
--> <anon>:2:30
|
2 | vec![0.0].iter().map(|s| s as i16).collect();
| ^^^^^^^^
|
= help: cast through a raw pointer first
error: aborting due to previous error
But casting through a raw pointer (s as *const f64 as *const i16 as i16
) is not the idiomatic way IMO. Instead it should be fixed by simply dereferencing:
vec![0.0].iter().map(|s| *s as i16).collect();