I have the following function:
fn f1(n: u8) -> u16 {
1 << n
}
I can try to (unsuccessfully) make it generic on integers:
extern crate num;
use num::Integer;
fn f1<T: Integer>(n: u8) -> T {
1 << n
}
This doesn't work. It generates the following error:
error[E0308]: mismatched types
--> src/main.rs:6:5
|
5 | fn f1<T: Integer>(n: u8) -> T {
| - expected `T` because of return type
6 | 1 << n
| ^^^^^^ expected type parameter, found integral variable
|
= note: expected type `T`
found type `{integer}`
I understand there is the Shl
trait. Do I need to use this trait to make this work? How would I do this?