mirror of
https://github.com/rust-lang/rustlings.git
synced 2024-12-27 00:00:03 +03:00
Learning about primitive data types
This commit is contained in:
parent
52ed5dbcf9
commit
f7678b4a9e
|
@ -2,8 +2,6 @@
|
||||||
// Fill in the rest of the line that has code missing!
|
// Fill in the rest of the line that has code missing!
|
||||||
// No hints, there's no tricks, just get used to typing these :)
|
// No hints, there's no tricks, just get used to typing these :)
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// Booleans (`bool`)
|
// Booleans (`bool`)
|
||||||
|
|
||||||
|
@ -12,7 +10,7 @@ fn main() {
|
||||||
println!("Good morning!");
|
println!("Good morning!");
|
||||||
}
|
}
|
||||||
|
|
||||||
let // Finish the rest of this line like the example! Or make it be false!
|
let is_evening = false; // Finish the rest of this line like the example! Or make it be false!
|
||||||
if is_evening {
|
if is_evening {
|
||||||
println!("Good evening!");
|
println!("Good evening!");
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,14 +2,12 @@
|
||||||
// Fill in the rest of the line that has code missing!
|
// Fill in the rest of the line that has code missing!
|
||||||
// No hints, there's no tricks, just get used to typing these :)
|
// No hints, there's no tricks, just get used to typing these :)
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// Characters (`char`)
|
// Characters (`char`)
|
||||||
|
|
||||||
// Note the _single_ quotes, these are different from the double quotes
|
// Note the _single_ quotes, these are different from the double quotes
|
||||||
// you've been seeing around.
|
// you've been seeing around.
|
||||||
let my_first_initial = 'C';
|
let my_first_initial = 'N';
|
||||||
if my_first_initial.is_alphabetic() {
|
if my_first_initial.is_alphabetic() {
|
||||||
println!("Alphabetical!");
|
println!("Alphabetical!");
|
||||||
} else if my_first_initial.is_numeric() {
|
} else if my_first_initial.is_numeric() {
|
||||||
|
@ -18,12 +16,12 @@ fn main() {
|
||||||
println!("Neither alphabetic nor numeric!");
|
println!("Neither alphabetic nor numeric!");
|
||||||
}
|
}
|
||||||
|
|
||||||
let // Finish this line like the example! What's your favorite character?
|
let my_favorite_character = '🔥'; // Finish this line like the example! What's your favorite character?
|
||||||
// Try a letter, try a number, try a special character, try a character
|
// Try a letter, try a number, try a special character, try a character
|
||||||
// from a different language than your own, try an emoji!
|
// from a different language than your own, try an emoji!
|
||||||
if your_character.is_alphabetic() {
|
if my_favorite_character.is_alphabetic() {
|
||||||
println!("Alphabetical!");
|
println!("Alphabetical!");
|
||||||
} else if your_character.is_numeric() {
|
} else if my_favorite_character.is_numeric() {
|
||||||
println!("Numerical!");
|
println!("Numerical!");
|
||||||
} else {
|
} else {
|
||||||
println!("Neither alphabetic nor numeric!");
|
println!("Neither alphabetic nor numeric!");
|
||||||
|
|
|
@ -2,10 +2,10 @@
|
||||||
// Create an array with at least 100 elements in it where the ??? is.
|
// Create an array with at least 100 elements in it where the ??? is.
|
||||||
// Execute `rustlings hint primitive_types3` or use the `hint` watch subcommand for a hint.
|
// Execute `rustlings hint primitive_types3` or use the `hint` watch subcommand for a hint.
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let a = ???
|
let a = ["Nidhal Messaoudi, A Rust professional!"; 100];
|
||||||
|
|
||||||
|
println!("{}", a.len());
|
||||||
|
|
||||||
if a.len() >= 100 {
|
if a.len() >= 100 {
|
||||||
println!("Wow, that's a big array!");
|
println!("Wow, that's a big array!");
|
||||||
|
|
|
@ -2,13 +2,11 @@
|
||||||
// Get a slice out of Array a where the ??? is so that the test passes.
|
// Get a slice out of Array a where the ??? is so that the test passes.
|
||||||
// Execute `rustlings hint primitive_types4` or use the `hint` watch subcommand for a hint.
|
// Execute `rustlings hint primitive_types4` or use the `hint` watch subcommand for a hint.
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn slice_out_of_array() {
|
fn slice_out_of_array() {
|
||||||
let a = [1, 2, 3, 4, 5];
|
let a = [1, 2, 3, 4, 5];
|
||||||
|
|
||||||
let nice_slice = ???
|
let nice_slice = &a[1..4];
|
||||||
|
|
||||||
assert_eq!([2, 3, 4], nice_slice)
|
assert_eq!([2, 3, 4], nice_slice)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,9 @@
|
||||||
// Destructure the `cat` tuple so that the println will work.
|
// Destructure the `cat` tuple so that the println will work.
|
||||||
// Execute `rustlings hint primitive_types5` or use the `hint` watch subcommand for a hint.
|
// Execute `rustlings hint primitive_types5` or use the `hint` watch subcommand for a hint.
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let cat = ("Furry McFurson", 3.5);
|
let cat = ("Furry McFurson", 3.5);
|
||||||
let /* your pattern here */ = cat;
|
let (name, age) = cat;
|
||||||
|
|
||||||
println!("{} is {} years old.", name, age);
|
println!("{} is {} years old.", name, age);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,13 +3,11 @@
|
||||||
// You can put the expression for the second element where ??? is so that the test passes.
|
// You can put the expression for the second element where ??? is so that the test passes.
|
||||||
// Execute `rustlings hint primitive_types6` or use the `hint` watch subcommand for a hint.
|
// Execute `rustlings hint primitive_types6` or use the `hint` watch subcommand for a hint.
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn indexing_tuple() {
|
fn indexing_tuple() {
|
||||||
let numbers = (1, 2, 3);
|
let numbers = (1, 2, 3);
|
||||||
// Replace below ??? with the tuple indexing syntax.
|
// Replace below ??? with the tuple indexing syntax.
|
||||||
let second = ???;
|
let second = numbers.1;
|
||||||
|
|
||||||
assert_eq!(2, second,
|
assert_eq!(2, second,
|
||||||
"This is not the 2nd number in the tuple!")
|
"This is not the 2nd number in the tuple!")
|
||||||
|
|
Loading…
Reference in a new issue