rearranged things

This commit is contained in:
Emily 2020-07-08 18:32:23 +10:00
parent c073ab0d91
commit cfe2547809
8 changed files with 28 additions and 22 deletions

5
examples/variables.txt Normal file
View File

@ -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

View File

@ -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);
}

View File

@ -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);
}

BIN
hello

Binary file not shown.

10
variables/.gitignore vendored
View File

@ -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

View File

@ -1,9 +0,0 @@
[package]
name = "variables"
version = "0.1.0"
authors = ["Emily J. <me@emily.im>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

View File

@ -1,3 +0,0 @@
fn main() {
println!("Hello, world!");
}