From 2dea1b048e0637346956b979f902dca88c48b616 Mon Sep 17 00:00:00 2001 From: Jordan Gong Date: Mon, 10 Aug 2020 21:35:16 +0800 Subject: Functions for fun --- functions/.gitignore | 18 ++++++++++++++++++ functions/Cargo.toml | 9 +++++++++ functions/src/main.rs | 28 ++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 functions/.gitignore create mode 100644 functions/Cargo.toml create mode 100644 functions/src/main.rs (limited to 'functions') diff --git a/functions/.gitignore b/functions/.gitignore new file mode 100644 index 0000000..e629269 --- /dev/null +++ b/functions/.gitignore @@ -0,0 +1,18 @@ + +# Created by https://www.toptal.com/developers/gitignore/api/rust +# Edit at https://www.toptal.com/developers/gitignore?templates=rust + +### Rust ### +# Generated by Cargo +# will have compiled files and executables +/target/ + +# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries +# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html +Cargo.lock + +# These are backup files generated by rustfmt +**/*.rs.bk + +# End of https://www.toptal.com/developers/gitignore/api/rust + diff --git a/functions/Cargo.toml b/functions/Cargo.toml new file mode 100644 index 0000000..e07244c --- /dev/null +++ b/functions/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "functions" +version = "0.1.0" +authors = ["Jordan Gong "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/functions/src/main.rs b/functions/src/main.rs new file mode 100644 index 0000000..c7a0db1 --- /dev/null +++ b/functions/src/main.rs @@ -0,0 +1,28 @@ +fn main() { + /* basic */ + println!("Hello, world!"); + + another_function(5, 6); + + /* expression */ + let y = { + let x = 3; + x + 1 + }; + + println!("The value of y is: {}", y); + + /* return */ + let x = plus_one(5); + + println!("The value of x is: {}", x); +} + +fn another_function(x: i32, y:i32) { + println!("The value of x is: {}", x); + println!("The value of y is: {}", y); +} + +fn plus_one(x: i32) -> i32 { + x + 1 +} -- cgit v1.2.3