Defining Functions
Parameters and returns.
Declaring a Function
You define a function with the fn keyword, a name, parentheses, and a body in curly braces.
Rust uses snake_case for function names by convention.
fn main() {
greet();
}
fn greet() {
println!("Hello from a function!");
}The main Function
Every executable Rust program starts at fn main(). It is the entry point the runtime calls first.
fn main() {
println!("Program starts here");
}All lessons in this course
- Defining Functions
- Expressions and Statements
- Closures
- Fn, FnMut, FnOnce