Expressions & Flow · 10 min · free with an account

Parameters

Lesson preview · about 30%

A function signature is a compact contract for every caller.

Core idea

Parameters need explicit types; arguments must satisfy them.

Start with the idea

Rust requires every parameter type to be written, which lets the body and every call be checked independently. Arguments are the concrete values passed at a call site; parameters are the named inputs in the definition. Passing an owned type may move it, while a reference lets the function borrow it — a distinction later lessons develop in depth.

In fn area(width: u32, height: u32), width and height are parameters: names the function uses inside its body. In area(4, 3), 4 and 3 are arguments: values supplied by one call. Rust checks that each argument can be used as the corresponding declared type. A literal often gains its type from this context, so you do not have to bind 4 to a separate u32 variable before calling area.

Order matters even when types match. area(4, 3) and area(3, 4) happen to return the same number, but a function such as subtract(left, right) would not.

Keep learning, for free

The rest of this lesson is waiting for you.

Create a free account to read the complete explanation, see the infographic, explore the code, and try the exercises. All 742 lessons and algorithm steps are included.

No payment details. Your account opens the complete Academy.

← All lessons in Rust Basics