first code in Rust
Today I woke up with a thought: learn Rust. I bought a book about 3 months ago and I started to read it, read code on GitHub etc but I never wrote a code by myself. After 1 hour (yeah, I suck) I implemented a fibonacci sequence. I think I used every Rust tips, but idk.
This is the bad code I wrote but I'm very proud of it.
use std::mem;
fn fib(n: &mut i32) -> i32 {
let mut a = 1;
let mut b = 1;
while *n > 1 {
a += b;
mem::swap(&mut a, &mut b);
*n -= 1;
}
b
}
This prints the first \(N\) numbers from the fibonacci code.
println!("{}", fib(&mut N));
Maybe one day I'll look at this code and think:"WTF is that?!".
Written on April 13, 2020