Python Functions, Parameters & Return Expressions
Functions in Rust are declared with fn. Parameters must have explicit type annotations. Rust is an expression-oriented language: blocks evaluate to their final expression, meaning omitting the trailing semicolon acts as an implicit return.
"In Rust, a function body is like an assembly line: steps ending in semicolons perform side effects, but the final un-punched part at the end of the belt is the finished product handed right back to the caller."
Deep Dive: How It Works
Statements vs Expressions: Statements perform an action and return () (e.g. let x = 5;). Expressions evaluate to a resulting value (e.g. 5 + 5).
Implicit Return: Omit the semicolon on the final line of a function to return that value.
Explicit Return: The return keyword is available for early exits from function bodies.
Syntax Blueprint
fn add(a: i32, b: i32) -> i32 { a + b }Notice no semicolon after a + b—this marks it as the returned expression.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Adding an accidental semicolon to the return expression.Why it happens: fn add(a: i32, b: i32) -> i32 { a + b; } returns () instead of i32, causing mismatched types error.
How to fix: Remove the trailing semicolon from the return expression.
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Write a multiply function
Write fn multiply(x: i32, y: i32) -> i32 that returns x * y without a semicolon.
In main(), call multiply(7, 8) and print "Product: 56".
Finished reading and practicing?
Mark this lesson as completed to update your course progress.