This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let mut i = 1_u8; | |
while i < 8 { | |
println!("Your number is: {}", i + 5); | |
i += 1; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum StagesInLife { | |
Birth(String), | |
Grow, | |
Work(String), | |
Retirement { age: u8, pension: f32 } | |
} | |
fn main() { | |
let work = StagesInLife::Work("Principal Software Engineer".to_string()); | |
match work { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let number = 35; | |
match number { | |
5 => println!("FIVE!"), | |
10..=15 => println!("This is the correct answer"), | |
_ => println!("If you don't match anything go here") | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let i = 8; | |
if i > 5 { | |
println!("{} is greater than 5", i); | |
} | |
if i < 8 { | |
println!("This line is not going to run"); | |
} else { | |
println!("But this does because its {}", i); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum StagesInLife { | |
Birth(String), | |
Grow, | |
Work(String), | |
Retirement { age: u8, pension: f32 } | |
} | |
fn main() { | |
let birth = StagesInLife::Birth("Jeff".to_string()); | |
let grow = StagesInLife::Grow; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Person { | |
name: String, | |
age: u8 | |
} | |
fn main() { | |
let person = Person { name: "Jeff", age: 35 }; | |
let name = String::from("Danny"); | |
let age = 11; | |
let another_person = Person { name, person }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let mut another_vec =!vec[5, 1,] ; // another_vec = [5, 1] | |
another_vec.push(2); // another_vec = [5, 1, 2] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let mut my_vec: Vec<i32> = Vec::new(); // my_vec = [] | |
my_vec.push(7); // my_vec = [7] | |
my_vec.push(8); // my_vec = [7, 8] | |
my_vec.push(7); // my_vec = [7, 8, 7] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let mut another_array: [i32:4] = [1,2,3,4]; | |
another_array[0] = 7; // another_array = [7, 2, 3, 4]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
// The next 6 lines are immutable variables | |
let an_int = 35; // Default is i32 | |
let another_int: u16 = 35_633; | |
let a_float: f32 = 2.56; | |
let another_float = 2.03_f64; | |
let my_bool = true; | |
let my_char = 'j'; | |
println!("{}", an_int); |