From 268453576d5a2d23bbe29c51d3ee4db26e9b491c Mon Sep 17 00:00:00 2001 From: Hammy Date: Wed, 12 Jan 2022 00:27:53 +0000 Subject: [PATCH] Add functions --- another_function/Cargo.toml | 8 ++++++++ another_function/src/main.rs | 23 +++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 another_function/Cargo.toml create mode 100644 another_function/src/main.rs diff --git a/another_function/Cargo.toml b/another_function/Cargo.toml new file mode 100644 index 0000000..e01bde8 --- /dev/null +++ b/another_function/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "another_function" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/another_function/src/main.rs b/another_function/src/main.rs new file mode 100644 index 0000000..b276aec --- /dev/null +++ b/another_function/src/main.rs @@ -0,0 +1,23 @@ +fn main() { + println!("Hello, world!"); + another_function(5); + print_labeled_measurement(5, 'h'); + println!("The value of x is -> {}", five()); + println!("The value of x is -> {}", plus_one(5)); +} + +fn another_function(x: i32) { + println!("The value of x is -> {}", x); +} + +fn print_labeled_measurement(value: i32, unit_label: char) { + println!("The measurement is: {}{}", value, unit_label); +} + +fn five() -> i32 { + 5 +} + +fn plus_one(x: i32) -> i32 { + x + 1 +} \ No newline at end of file