1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
extern crate num; use num::{Integer, Unsigned}; fn fibonacci<T: Integer + Unsigned>(n: T) -> T { match n { 0 => 0, 1 => 1, _ => n + fibonacci(n-1), } } fn main() { let n = 10; println!("{}", fibonacci(n as u16)); println!("{}", fibonacci(n as u64)); }