How would I do the following if Rust supported two percent
functions?
fn percent(x: u8) -> f32 {
x as f32 / 100.0
}
fn percent(x: u16) -> f32 {
x as f32 / 100.0
}
If I try a generic data type like the following:
fn percent<T>(x: T) -> f32 {
x as f32 / 100.0
}
I get the error
non-primitive cast:
T
asf32
Can I constrain T
with some kind of integer trait?