Skip to content
Closed

Dev #2356

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion exercises/00_intro/intro2.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
fn main() {
// TODO: Fix the code to print "Hello world!".
printline!("Hello world!");
println!("Hello world!");
}
2 changes: 1 addition & 1 deletion exercises/01_variables/variables1.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
fn main() {
// TODO: Add the missing keyword.
x = 5;
let x = 5;

println!("x has the value {x}");
}
4 changes: 2 additions & 2 deletions exercises/01_variables/variables2.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
fn main() {
// TODO: Change the line below to fix the compiler error.
let x;
let x = 42;

if x == 10 {
if 10 == x {
println!("x is ten!");
} else {
println!("x is not ten!");
Expand Down
2 changes: 1 addition & 1 deletion exercises/01_variables/variables3.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
fn main() {
// TODO: Change the line below to fix the compiler error.
let x: i32;
let x: i32 = 42;

println!("Number {x}");
}
2 changes: 1 addition & 1 deletion exercises/01_variables/variables4.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// TODO: Fix the compiler error.
fn main() {
let x = 3;
let mut x = 3;
println!("Number {x}");

x = 5; // Don't change this line
Expand Down
4 changes: 2 additions & 2 deletions exercises/01_variables/variables5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ fn main() {
println!("Spell a number: {number}");

// TODO: Fix the compiler error by changing the line below without renaming the variable.
number = 3;
println!("Number plus two is: {}", number + 2);
let number2 = 3;
println!("Number plus two is: {}", number2 + 2);
}
2 changes: 1 addition & 1 deletion exercises/01_variables/variables6.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// TODO: Change the line below to fix the compiler error.
const NUMBER = 3;
const NUMBER: i32 = 3;

fn main() {
println!("Number: {NUMBER}");
Expand Down
4 changes: 3 additions & 1 deletion exercises/02_functions/functions1.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// TODO: Add some function with the name `call_me` without arguments or a return value.

fn call_me() {
println!("You called me!");
}
fn main() {
call_me(); // Don't change this line
}
2 changes: 1 addition & 1 deletion exercises/02_functions/functions2.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// TODO: Add the missing type of the argument `num` after the colon `:`.
fn call_me(num:) {
fn call_me(num:u32) {
for i in 0..num {
println!("Ring! Call number {}", i + 1);
}
Expand Down
2 changes: 1 addition & 1 deletion exercises/02_functions/functions3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ fn call_me(num: u8) {

fn main() {
// TODO: Fix the function call.
call_me();
call_me(1);
}
2 changes: 1 addition & 1 deletion exercises/02_functions/functions4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn is_even(num: i64) -> bool {
}

// TODO: Fix the function signature.
fn sale_price(price: i64) -> {
fn sale_price(price: i64) -> i64{
if is_even(price) {
price - 10
} else {
Expand Down
2 changes: 1 addition & 1 deletion exercises/02_functions/functions5.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// TODO: Fix the function body without changing the signature.
fn square(num: i32) -> i32 {
num * num;
num * num
}

fn main() {
Expand Down
5 changes: 5 additions & 0 deletions exercises/03_if/if1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ fn bigger(a: i32, b: i32) -> i32 {
// Do not use:
// - another function call
// - additional variables
if a > b {
a
} else {
b
}
}

fn main() {
Expand Down
4 changes: 3 additions & 1 deletion exercises/03_if/if2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
fn picky_eater(food: &str) -> &str {
if food == "strawberry" {
"Yummy!"
} else if food == "potato" {
"I guess I can eat that."
} else {
1
"No thanks!"
}
}

Expand Down
6 changes: 3 additions & 3 deletions exercises/03_if/if3.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
fn animal_habitat(animal: &str) -> &str {
// TODO: Fix the compiler error in the statement below.
let identifier = if animal == "crab" {
1
1
} else if animal == "gopher" {
2.0
2
} else if animal == "snake" {
3
} else {
"Unknown"
4
};

// Don't change the expression below!
Expand Down
1 change: 1 addition & 0 deletions exercises/04_primitive_types/primitive_types1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ fn main() {
// TODO: Define a boolean variable with the name `is_evening` before the `if` statement below.
// The value of the variable should be the negation (opposite) of `is_morning`.
// let …
let is_evening = !is_morning;
if is_evening {
println!("Good evening!");
}
Expand Down
2 changes: 1 addition & 1 deletion exercises/04_primitive_types/primitive_types2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn main() {
// Try a letter, try a digit (in single quotes), try a special character, try a character
// from a different language than your own, try an emoji 😉
// let your_character = '';

let your_character = '😊';
if your_character.is_alphabetic() {
println!("Alphabetical!");
} else if your_character.is_numeric() {
Expand Down
2 changes: 1 addition & 1 deletion exercises/04_primitive_types/primitive_types3.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
fn main() {
// TODO: Create an array called `a` with at least 100 elements in it.
// let a = ???

let a = [0; 100];
if a.len() >= 100 {
println!("Wow, that's a big array!");
} else {
Expand Down
1 change: 1 addition & 0 deletions exercises/04_primitive_types/primitive_types4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ mod tests {

// TODO: Get a slice called `nice_slice` out of the array `a` so that the test passes.
// let nice_slice = ???
let nice_slice = &a[1..4];

assert_eq!([2, 3, 4], nice_slice);
}
Expand Down
1 change: 1 addition & 0 deletions exercises/04_primitive_types/primitive_types5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ fn main() {

// TODO: Destructure the `cat` tuple in one statement so that the println works.
// let /* your pattern here */ = cat;
let (name, age) = cat;

println!("{name} is {age} years old");
}
1 change: 1 addition & 0 deletions exercises/04_primitive_types/primitive_types6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ mod tests {
// TODO: Use a tuple index to access the second element of `numbers`
// and assign it to a variable called `second`.
// let second = ???;
let second = numbers.1;

assert_eq!(second, 2, "This is not the 2nd number in the tuple!");
}
Expand Down
1 change: 1 addition & 0 deletions exercises/05_vecs/vecs1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ fn array_and_vec() -> ([i32; 4], Vec<i32>) {
// TODO: Create a vector called `v` which contains the exact same elements as in the array `a`.
// Use the vector macro.
// let v = ???;
let v = vec![10, 20, 30, 40]; // Vector

(a, v)
}
Expand Down
1 change: 1 addition & 0 deletions exercises/05_vecs/vecs2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ fn vec_loop(input: &[i32]) -> Vec<i32> {
for element in input {
// TODO: Multiply each element in the `input` slice by 2 and push it to
// the `output` vector.
output.push(element * 2);
}

output
Expand Down
2 changes: 1 addition & 1 deletion exercises/06_move_semantics/move_semantics1.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// TODO: Fix the compiler error in this function.
fn fill_vec(vec: Vec<i32>) -> Vec<i32> {
let vec = vec;
let mut vec = vec;

vec.push(88);

Expand Down
2 changes: 1 addition & 1 deletion exercises/06_move_semantics/move_semantics2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ mod tests {
fn move_semantics2() {
let vec0 = vec![22, 44, 66];

let vec1 = fill_vec(vec0);
let vec1 = fill_vec(vec0.clone());

assert_eq!(vec0, [22, 44, 66]);
assert_eq!(vec1, [22, 44, 66, 88]);
Expand Down
2 changes: 1 addition & 1 deletion exercises/06_move_semantics/move_semantics3.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// TODO: Fix the compiler error in the function without adding any new line.
fn fill_vec(vec: Vec<i32>) -> Vec<i32> {
fn fill_vec(mut vec: Vec<i32>) -> Vec<i32> {
vec.push(88);

vec
Expand Down
5 changes: 4 additions & 1 deletion exercises/06_move_semantics/move_semantics4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ mod tests {
#[test]
fn move_semantics4() {
let mut x = Vec::new();

let y = &mut x;
let z = &mut x;
y.push(42);
let z = &mut x;
z.push(13);


assert_eq!(x, [42, 13]);
}
}
6 changes: 3 additions & 3 deletions exercises/06_move_semantics/move_semantics5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn get_char(data: String) -> char {
}

// Should take ownership
fn string_uppercase(mut data: &String) {
fn string_uppercase(mut data: String) {
data = data.to_uppercase();

println!("{data}");
Expand All @@ -18,7 +18,7 @@ fn string_uppercase(mut data: &String) {
fn main() {
let data = "Rust is great!".to_string();

get_char(data);
get_char(data.clone());

string_uppercase(&data);
string_uppercase(data);
}
8 changes: 8 additions & 0 deletions exercises/quizzes/quiz1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
// the quantity bought.
// fn calculate_price_of_apples(???) -> ??? { ??? }

fn calculate_price_of_apples(quantity: i32) -> i32 {
if quantity > 40 {
quantity
} else {
quantity * 2
}
}

fn main() {
// You can optionally experiment here.
}
Expand Down
2 changes: 1 addition & 1 deletion release-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
set -e

typos
cargo upgrades
# cargo upgrades

# Similar to CI
cargo clippy -- --deny warnings
Expand Down
Loading