Sometimes you want it to be lossy, but not most of the time, and yet there is no choice. I had a bug caused by that, that's why I remember it. Silent explicit type conversions are essentially unsafe.
fn main() {
let x = 5i32;
let y: i64 = x.into();
println!("{}", y);
}
this doesn't work: fn main() {
let x = 5i32;
let y: i16 = x.into();
println!("{}", y);
}
you have to write: fn main() {
let x = 5i32;
let y = x as i16;
println!("{}", y);
}
where `as` has the potential of being lossy!The casting function could specify the valid input values, and force the programmer to handle the rest of the cases when the input type is wider.
This is a contradiction, something cannot be both silent and explicit.