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.
Read the code
fn area(width: u32, height: u32) -> u32 {
width * height
}
let result = area(4, 3);Both inputs and the output are visible before reading the body.
Practice starter
fn double(value: u32) -> u32 {
value * 2
}
let answer = double("4");
Work through it
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. Choose parameter names that tell the reader which role each value plays, and use a struct when a call would otherwise contain many similar-looking arguments. The body can then focus on computation, while the signature communicates the input contract to every caller.
The ownership aspect becomes more important with non-Copy values. Passing a String by value normally transfers ownership to the function; passing &str lets it borrow text for reading. At this stage, inspect the parameter type rather than assuming a call always copies. Add a third argument to area and read the arity diagnostic, then pass text where a u32 is expected and compare that type diagnostic. Each points to a different part of the same contract.
Try a function that takes a String, and call it twice with the same value. If the first call owns its parameter, the second call exposes the move clearly. Change the parameter to &str when reading is enough, then pass both a string literal and a borrowed String to verify the flexible interface.
At a call site, arguments must match the function's parameter types and order. A function that accepts &str borrows text; one that accepts String takes ownership of a growable string. This affects what the caller can do afterward. The signature is therefore more than documentation: it is an enforceable contract about both values and ownership.
For each parameter in the example, label whether the function reads it, mutates through it, or owns it. width and height are plain u32 copies that the body only reads. When a function only needs to read a string, pass a borrowed &str instead of moving a String. Then try swapping two same-typed arguments and notice that the compiler cannot catch a semantic mix-up just because their types match. Named domain types or a small struct can make such calls safer. When designing a function, choose the least ownership it needs and make the result or error explicit.
Try it
Write a two-parameter function and call it with matching arguments.
What success looks like: The signature communicates exactly which values enter and leave.
Check your understanding
Why is the call rejected?
Reveal the answer
- The argument is &str but the parameter is u32
- A literal has to be bound to a variable first
- double must return the same type it accepts
The call site must provide the u32 promised by the parameter type.
Learn this lesson with AI
Paste this into Claude, Codex, Cursor or another agent connected to Crabrix Academy. It contains only this lesson’s public details.
I'm learning Rust with Crabrix Academy. Teach me this lesson with the Crabrix Academy tools. Lesson: Parameters (courseId "basics", lessonId "function-parameters") Link: https://crabrix.com/learn/basics/function-parameters/ Goal: Parameters need explicit types; arguments must satisfy them. Practice: open the starter in the Crabrix Playground (https://crabrix.com/playground/?lesson=basics/function-parameters) and I will write the code there. Explain it step by step for my level, let me write the code myself, give hints before any solution, and do not mark anything as passed: only Crabrix checks do that.