From 6e4f0b4c6d7f7ad0eaaae5f4f2e2f3a08881ee35 Mon Sep 17 00:00:00 2001 From: Jordan Gong Date: Tue, 4 Aug 2020 18:41:09 +0800 Subject: Play around with variables --- variables/.gitignore | 18 ++++++++++++++++++ variables/Cargo.toml | 9 +++++++++ variables/src/main.rs | 16 ++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 variables/.gitignore create mode 100644 variables/Cargo.toml create mode 100644 variables/src/main.rs (limited to 'variables') diff --git a/variables/.gitignore b/variables/.gitignore new file mode 100644 index 0000000..e629269 --- /dev/null +++ b/variables/.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/variables/Cargo.toml b/variables/Cargo.toml new file mode 100644 index 0000000..cee94d1 --- /dev/null +++ b/variables/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "variables" +version = "0.1.0" +authors = ["jordan"] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/variables/src/main.rs b/variables/src/main.rs new file mode 100644 index 0000000..3a4394a --- /dev/null +++ b/variables/src/main.rs @@ -0,0 +1,16 @@ +fn main() { + /* mutability */ + let mut x = 5; + println!("The variable of x is: {}", x); + x = 6; + println!("The variable of x is: {}", x); + + /* shadowing */ + let x = 5; + + let x = x + 1; + + let x = x * 2; + + println!("The value of x is: {}", x); +} -- cgit v1.2.3