April 2026
Intermediate
631 pages
16h 20m
English
At this point, you’ve already encountered functions in Rust, specifically the main function.
Functions in Rust are declared using the fn keyword, followed by the function name, parentheses (which can contain input parameters), and finally curly braces that enclose the function’s body. The following code defines a function:
fn my_fn(s: &str) { println!("{s}");}
The naming convention for functions in Rust is snake_case, meaning everything is written in lowercase with an underscore between words. Parameters are defined like variables, with the variable name followed by a type annotation. We can add more parameters by simply separating them with a comma and using the same syntax. In this case, the function takes a string slice ...
Read now
Unlock full access