Skip to content

Commit f7678b4

Browse files
Learning about primitive data types
1 parent 52ed5db commit f7678b4

File tree

6 files changed

+11
-21
lines changed

6 files changed

+11
-21
lines changed

exercises/primitive_types/primitive_types1.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// Fill in the rest of the line that has code missing!
33
// No hints, there's no tricks, just get used to typing these :)
44

5-
// I AM NOT DONE
6-
75
fn main() {
86
// Booleans (`bool`)
97

@@ -12,7 +10,7 @@ fn main() {
1210
println!("Good morning!");
1311
}
1412

15-
let // Finish the rest of this line like the example! Or make it be false!
13+
let is_evening = false; // Finish the rest of this line like the example! Or make it be false!
1614
if is_evening {
1715
println!("Good evening!");
1816
}

exercises/primitive_types/primitive_types2.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22
// Fill in the rest of the line that has code missing!
33
// No hints, there's no tricks, just get used to typing these :)
44

5-
// I AM NOT DONE
6-
75
fn main() {
86
// Characters (`char`)
97

108
// Note the _single_ quotes, these are different from the double quotes
119
// you've been seeing around.
12-
let my_first_initial = 'C';
10+
let my_first_initial = 'N';
1311
if my_first_initial.is_alphabetic() {
1412
println!("Alphabetical!");
1513
} else if my_first_initial.is_numeric() {
@@ -18,12 +16,12 @@ fn main() {
1816
println!("Neither alphabetic nor numeric!");
1917
}
2018

21-
let // Finish this line like the example! What's your favorite character?
19+
let my_favorite_character = '🔥'; // Finish this line like the example! What's your favorite character?
2220
// Try a letter, try a number, try a special character, try a character
2321
// from a different language than your own, try an emoji!
24-
if your_character.is_alphabetic() {
22+
if my_favorite_character.is_alphabetic() {
2523
println!("Alphabetical!");
26-
} else if your_character.is_numeric() {
24+
} else if my_favorite_character.is_numeric() {
2725
println!("Numerical!");
2826
} else {
2927
println!("Neither alphabetic nor numeric!");

exercises/primitive_types/primitive_types3.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
// Create an array with at least 100 elements in it where the ??? is.
33
// Execute `rustlings hint primitive_types3` or use the `hint` watch subcommand for a hint.
44

5-
// I AM NOT DONE
6-
75
fn main() {
8-
let a = ???
6+
let a = ["Nidhal Messaoudi, A Rust professional!"; 100];
7+
8+
println!("{}", a.len());
99

1010
if a.len() >= 100 {
1111
println!("Wow, that's a big array!");

exercises/primitive_types/primitive_types4.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22
// Get a slice out of Array a where the ??? is so that the test passes.
33
// Execute `rustlings hint primitive_types4` or use the `hint` watch subcommand for a hint.
44

5-
// I AM NOT DONE
6-
75
#[test]
86
fn slice_out_of_array() {
97
let a = [1, 2, 3, 4, 5];
108

11-
let nice_slice = ???
9+
let nice_slice = &a[1..4];
1210

1311
assert_eq!([2, 3, 4], nice_slice)
1412
}

exercises/primitive_types/primitive_types5.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
// Destructure the `cat` tuple so that the println will work.
33
// Execute `rustlings hint primitive_types5` or use the `hint` watch subcommand for a hint.
44

5-
// I AM NOT DONE
6-
75
fn main() {
86
let cat = ("Furry McFurson", 3.5);
9-
let /* your pattern here */ = cat;
7+
let (name, age) = cat;
108

119
println!("{} is {} years old.", name, age);
1210
}

exercises/primitive_types/primitive_types6.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33
// You can put the expression for the second element where ??? is so that the test passes.
44
// Execute `rustlings hint primitive_types6` or use the `hint` watch subcommand for a hint.
55

6-
// I AM NOT DONE
7-
86
#[test]
97
fn indexing_tuple() {
108
let numbers = (1, 2, 3);
119
// Replace below ??? with the tuple indexing syntax.
12-
let second = ???;
10+
let second = numbers.1;
1311

1412
assert_eq!(2, second,
1513
"This is not the 2nd number in the tuple!")

0 commit comments

Comments
 (0)