0PricingLogin
Learn Rust Coding · Lesson

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

  1. Defining Functions
  2. Expressions and Statements
  3. Closures
  4. Fn, FnMut, FnOnce
← Back to Learn Rust Coding