Define Rust functions using the fn keyword, specifying argument types and optional return types within curly braces.
You define a function in Rust using the fn keyword, followed by the function name, parentheses for arguments, and curly braces for the body.
fn main() {
println!("Hello, world!");
}
fn add(x: i32, y: i32) -> i32 {
x + y
}
The fn keyword starts the definition, main is the entry point, and add demonstrates parameters with types (i32) and a return type (-> i32).
A function is a named block of code that performs a specific task, like a recipe for cooking a dish. You define it once so you can reuse the logic whenever you need it without rewriting the steps. In Rust, you must specify exactly what ingredients (arguments) it needs and what it produces (return value) before you use it.