summaryrefslogtreecommitdiff
path: root/meap/meap-code/ch5/ch5-genfib/src/main.rs
blob: e3c95e038c22e071ef04e4328ef396f9de444454 (plain) (blame)
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));
}