Rust
Rust
Installation
Ubuntu
apt install rustc
Alma Linux
dnf install rust
Arch Linux
pacman -S rust
Binary
# Download rust-{version}-{arch}-{os}.tar.gz from https://rust-lang.org
tar xzf rust-{version}-{arch}-{os}.tar.gz
cd rust-{version}
./install.sh
Examples
Fibonacci Numbers
// Fibonacci Numbers
use std::env;
fn fib(n: i64) -> i64 {
if n < 2 {
n
} else {
fib(n - 1) + fib(n - 2)
}
}
fn main() {
if let Some(s) = env::args().nth(1) {
if let Ok(n) = s.parse::<i64>() {
println!("{}", fib(n))
}
}
}
/*
example
compile:
rustc -C opt-level=3 fib.rs
run:
./fib 39
*/