summaryrefslogtreecommitdiff
path: root/variables
diff options
context:
space:
mode:
authorJordan Gong <jordan@inspiron-n4050.localdomain>2020-08-04 18:41:09 +0800
committerJordan Gong <jordan@inspiron-n4050.localdomain>2020-08-04 18:41:09 +0800
commit6e4f0b4c6d7f7ad0eaaae5f4f2e2f3a08881ee35 (patch)
treeb73ebd8428768a403e904ca4382fed623b566010 /variables
parentea8b1af82ff12a1961723b84969d2e5ad27491e9 (diff)
Play around with variables
Diffstat (limited to 'variables')
-rw-r--r--variables/.gitignore18
-rw-r--r--variables/Cargo.toml9
-rw-r--r--variables/src/main.rs16
3 files changed, 43 insertions, 0 deletions
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);
+}