Search⌘ K

Anatomy of a Function

Explore the structure of Rust functions by examining their names, parameters, return types, and bodies. Understand how to define and call functions like subtract and greet, and apply this knowledge by creating practical examples.

We'll cover the following...

Alright, time to review what we know about functions and how they’re put together. From what we’ve seen, functions consist of:

Let’s look at some examples of this:

Rust 1.40.0
fn subtract(x: i32, y: i32) -> i32 {
x - y
}

The function name is subtract. It has a parameter list with two parameters. ...