published: 29th of January 2022
Rust is a functional language, it may or may not be shocking to discover that functions are a big part of the language.
A function is defined with the fn keyword. fn is pronounced: fun 🥳
// Function with no parameters or return value
fn stuff() {
println!("stuff"); // => stuff
}
// Function with parameters that returns an i32
fn add(i: i32, j: i32) -> i32 {
// return i + j; // supported, but not preferred.
i + j // bare tail expression is perferred.
}
// The `main` function is the programs entry point.
fn main() {
stuff(); // call a function.
println!("{}", add(1, 2)); // => 3
}
https://www.manning.com/books/rust-in-action
https://www.udemy.com/course/ultimate-rust-crash-course/