mirror of
https://github.com/ArthurDanjou/hellorust.git
synced 2026-01-14 12:14:35 +01:00
Learn functions
This commit is contained in:
29
src/functions.rs
Normal file
29
src/functions.rs
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
fn main() {
|
||||||
|
println!("Hello, world!");
|
||||||
|
an_other_function(12);
|
||||||
|
print_value_with_unite(5, 'h');
|
||||||
|
statements();
|
||||||
|
println!("The value of five() is {}", five());
|
||||||
|
}
|
||||||
|
|
||||||
|
fn an_other_function(x: u32) {
|
||||||
|
println!("Another function");
|
||||||
|
println!("The value of x is: {}", x);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn print_value_with_unite(value: i32, unit: char) {
|
||||||
|
println!("The value is: {}{}", value, unit);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn statements() {
|
||||||
|
let y = {
|
||||||
|
let x = 3;
|
||||||
|
x + 1
|
||||||
|
};
|
||||||
|
|
||||||
|
println!("The value of y is: {}", y);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn five() -> i32 {
|
||||||
|
5
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user