Search⌘ K

Calling Functions

Explore how to call functions in Rust by providing the function name and parameters. Learn to pass variables, literals, or expressions as arguments and nest function calls for more efficient code.

We'll cover the following...

Let’s go into a bit more depth on how to call a function. Let’s see an example:

Rust 1.40.0
fn greet(name: &str) {
println!("Hello {}", name);
}
fn main() {
greet("Michael");
}

In order to call a function, we put the name of the function, followed by an open parenthesis, then the parameter list, then by a close parenthesis. A function call itself is an expression, a fact we’ll ...