diff --git a/hello.rs b/examples/hello.rs similarity index 100% rename from hello.rs rename to examples/hello.rs diff --git a/examples/variables.txt b/examples/variables.txt new file mode 100644 index 0000000..8734b96 --- /dev/null +++ b/examples/variables.txt @@ -0,0 +1,5 @@ +- Variables are immutable by default +- Normal variables can have their value reassigned, mutable variables must keep the same type + and immutable variables can have their values reassigned using let again, also allowing you + to change the type (shadowing) +- Constant variables cannot have new variables reassigned to the name they use diff --git a/examples/variables_mutable.rs b/examples/variables_mutable.rs new file mode 100644 index 0000000..74919ee --- /dev/null +++ b/examples/variables_mutable.rs @@ -0,0 +1,12 @@ +/* + * x is defined as an mutable variable, the value is reassigned again later without redfining it. + * mutable variables are assigned one type, and the variable cannot be any other type other than the + * one it was originally assigned. +*/ + +fn main() { + let x = 5; + println!("The value of x is: {}", x); + let x = 6; + println!("The value of x is: {}", x); +} diff --git a/examples/variables_shadow.rs b/examples/variables_shadow.rs new file mode 100644 index 0000000..eb2f8ed --- /dev/null +++ b/examples/variables_shadow.rs @@ -0,0 +1,11 @@ +/* + * x is defined as an immutable variable, then defined again later (shadowed?) + * redefining a variable like this lets you change the type. +*/ + +fn main() { + let x = 5; + println!("The value of x is: {}", x); + let x = 6; + println!("The value of x is: {}", x); +} diff --git a/hello b/hello deleted file mode 100755 index 5becca1..0000000 Binary files a/hello and /dev/null differ diff --git a/variables/.gitignore b/variables/.gitignore deleted file mode 100644 index 0039f28..0000000 --- a/variables/.gitignore +++ /dev/null @@ -1,10 +0,0 @@ -# will have compiled files and executables -debug/ -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 \ No newline at end of file diff --git a/variables/Cargo.toml b/variables/Cargo.toml deleted file mode 100644 index 7d89f0b..0000000 --- a/variables/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "variables" -version = "0.1.0" -authors = ["Emily J. "] -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 deleted file mode 100644 index e7a11a9..0000000 --- a/variables/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("Hello, world!"); -}