Rust Functions Tutorial | Parameters & Return Values for Beginners (2026)
3views
004:58
T
Taught by Celeste AI - AI Coding Coach
View on YouTubeDescription
Learn how to create and use functions in Rust! This beginner tutorial covers basic functions, parameters, and return values with clear code explanations.
š„ In This Tutorial:
āāāāāāāāāāāāāāāāāāāāāāā
0:00 - Intro
0:06 - Basic Functions (fn keyword)
1:38 - Function Parameters (&str)
3:08 - Return Values (arrow type)
4:51 - Outro
š What You'll Learn:
āāāāāāāāāāāāāāāāāāāāāāā
ā
Create functions with the fn keyword
ā
Call functions from main()
ā
Pass parameters to functions
ā
Use &str for string parameters
ā
Return values with arrow syntax
ā
Implicit return (no semicolon)
š» Code Examples:
āāāāāāāāāāāāāāāāāāāāāāā
// Basic function
fn greet() {
println!("Hello from a function!");
}
// Function with parameter
fn greet(name: &str) {
println!("Hello, {}!", name);
}
// Function with return value
fn add(a: i32, b: i32) returns i32 {
a + b // No semicolon = return!
}
ā” Key Concepts:
āāāāāāāāāāāāāāāāāāāāāāā
ā Functions are defined with 'fn'
ā Parameters have type annotations: name: &str
ā Return type uses arrow syntax
ā Last expression without semicolon is returned
ā main() is always the entry point
š ļø Tools Used:
āāāāāāāāāāāāāāāāāāāāāāā
ā rustc (Rust compiler)
ā nvim (code editor)
š Like & Subscribe for more Rust tutorials!
#rust #rustlang #programming #functions #tutorial #beginners #coding #learnrust
Back to tutorialsOpen in YouTube
Duration
4:58
Published
December 21, 2025
Added to Codegiz
March 15, 2026