From 9daf4cdea2270cb810f0ad9eff247e2d1398fe33 Mon Sep 17 00:00:00 2001 From: Arthur DANJOU Date: Sun, 14 Nov 2021 23:18:04 +0100 Subject: [PATCH] Learn functions --- src/functions.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/functions.rs diff --git a/src/functions.rs b/src/functions.rs new file mode 100644 index 0000000..cb11fbc --- /dev/null +++ b/src/functions.rs @@ -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 +} \ No newline at end of file