From 87c44a3bc88c802866535f068739334d1fa96980 Mon Sep 17 00:00:00 2001 From: Enrico Bozzolini Date: Thu, 1 Jan 2026 22:12:39 +0100 Subject: [PATCH] update from upstream --- exercises/clippy/clippy1.rs | 17 ++++++++ exercises/conversions/from_into.rs | 7 +++ exercises/conversions/using_as.rs | 8 ++++ exercises/enums/enums3.rs | 11 +++++ exercises/error_handling/errors1.rs | 11 +++++ exercises/error_handling/errors4.rs | 2 +- exercises/functions/functions2.rs | 12 ++++++ exercises/generics/generics2.rs | 8 ++++ exercises/if/if1.rs | 3 ++ exercises/if/if2.rs | 6 +++ exercises/macros/macros4.rs | 6 +++ exercises/modules/modules1.rs | 10 +++++ exercises/modules/modules2.rs | 6 +++ exercises/primitive_types/primitive_types2.rs | 6 +++ exercises/primitive_types/primitive_types6.rs | 13 ++++++ exercises/quiz3.rs | 43 +++++++++++++++++++ exercises/structs/structs1.rs | 6 +++ exercises/structs/structs3.rs | 14 ++++++ exercises/threads/threads1.rs | 19 ++++---- exercises/traits/traits1.rs | 9 ++++ exercises/traits/traits2.rs | 4 ++ exercises/variables/variables3.rs | 4 ++ exercises/variables/variables4.rs | 6 +++ exercises/variables/variables5.rs | 7 +++ 24 files changed, 228 insertions(+), 10 deletions(-) diff --git a/exercises/clippy/clippy1.rs b/exercises/clippy/clippy1.rs index 38463601..d1166816 100644 --- a/exercises/clippy/clippy1.rs +++ b/exercises/clippy/clippy1.rs @@ -9,10 +9,27 @@ // Execute `rustlings hint clippy1` or use the `hint` watch subcommand for a // hint. +<<<<<<< HEAD fn main() { let x = 1.2331f64; let y = 1.2332f64; if (x - y).abs() < 0.00001 { println!("Success!"); } +======= +// I AM NOT DONE + +use std::f32; + +fn main() { + let pi = 3.14f32; + let radius = 5.00f32; + + let area = pi * f32::powi(radius, 2); + + println!( + "The area of a circle with radius {:.2} is {:.5}!", + radius, area + ) +>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e } diff --git a/exercises/conversions/from_into.rs b/exercises/conversions/from_into.rs index c4899825..ea4eced7 100644 --- a/exercises/conversions/from_into.rs +++ b/exercises/conversions/from_into.rs @@ -24,11 +24,18 @@ impl Default for Person { } } +<<<<<<< HEAD // Your task is to complete this implementation // in order for the line `let p = Person::from("Mark,20")` to compile // Please note that you'll need to parse the age component into a `usize` // with something like `"4".parse::()`. The outcome of this needs to // be handled appropriately. +======= +// Your task is to complete this implementation in order for the line `let p = +// Person::from("Mark,20")` to compile Please note that you'll need to parse the +// age component into a `usize` with something like `"4".parse::()`. The +// outcome of this needs to be handled appropriately. +>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e // // Steps: // 1. If the length of the provided string is 0, then return the default of diff --git a/exercises/conversions/using_as.rs b/exercises/conversions/using_as.rs index ce15bcad..c5cdce08 100644 --- a/exercises/conversions/using_as.rs +++ b/exercises/conversions/using_as.rs @@ -10,12 +10,20 @@ // Execute `rustlings hint using_as` or use the `hint` watch subcommand for a // hint. +<<<<<<< HEAD // The goal is to make sure that the division does not fail to compile fn average(values: &[f64]) -> f64 { let total = values .iter() .fold(0.0, |a, b| a + b); total / (values.len() as f64) +======= +// I AM NOT DONE + +fn average(values: &[f64]) -> f64 { + let total = values.iter().sum::(); + total / values.len() +>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e } fn main() { diff --git a/exercises/enums/enums3.rs b/exercises/enums/enums3.rs index eb4ffaf9..cd39e670 100644 --- a/exercises/enums/enums3.rs +++ b/exercises/enums/enums3.rs @@ -41,6 +41,7 @@ impl State { } fn process(&mut self, message: Message) { +<<<<<<< HEAD // TODO: create a match expression to process the different message variants match message { Message::ChangeColor(r, g, b) => self.change_color((r, g, b)), @@ -51,6 +52,12 @@ impl State { }, _ => self.quit(), } +======= + // TODO: create a match expression to process the different message + // variants + // Remember: When passing a tuple as a function argument, you'll need + // extra parentheses: fn function((t, u, p, l, e)) +>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e } } @@ -68,7 +75,11 @@ mod tests { }; state.process(Message::ChangeColor(255, 0, 255)); state.process(Message::Echo(String::from("hello world"))); +<<<<<<< HEAD state.process(Message::Move{ x: 10, y: 15 }); +======= + state.process(Message::Move(Point { x: 10, y: 15 })); +>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e state.process(Message::Quit); assert_eq!(state.color, (255, 0, 255)); diff --git a/exercises/error_handling/errors1.rs b/exercises/error_handling/errors1.rs index e64ef7d4..0e027dce 100644 --- a/exercises/error_handling/errors1.rs +++ b/exercises/error_handling/errors1.rs @@ -9,12 +9,23 @@ // Execute `rustlings hint errors1` or use the `hint` watch subcommand for a // hint. +<<<<<<< HEAD pub fn generate_nametag_text(name: String) -> Result { if name.len() > 0 { Ok(format!("Hi! My name is {}", name)) } else { // Empty names aren't allowed. Err("`name` was empty; it must be nonempty.".into()) +======= +// I AM NOT DONE + +pub fn generate_nametag_text(name: String) -> Option { + if name.is_empty() { + // Empty names aren't allowed. + None + } else { + Some(format!("Hi! My name is {}", name)) +>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e } } diff --git a/exercises/error_handling/errors4.rs b/exercises/error_handling/errors4.rs index 6f003f05..d8bdba6a 100644 --- a/exercises/error_handling/errors4.rs +++ b/exercises/error_handling/errors4.rs @@ -8,7 +8,7 @@ struct PositiveNonzeroInteger(u64); #[derive(PartialEq, Debug)] enum CreationError { - Negative, + Negative, Zero, } diff --git a/exercises/functions/functions2.rs b/exercises/functions/functions2.rs index 92dac557..6d0a20e9 100644 --- a/exercises/functions/functions2.rs +++ b/exercises/functions/functions2.rs @@ -1,11 +1,23 @@ // functions2.rs +<<<<<<< HEAD // Make me compile! Execute `rustlings hint functions2` for hints :)s +======= +// +// Execute `rustlings hint functions2` or use the `hint` watch subcommand for a +// hint. + +// I AM NOT DONE +>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e fn main() { call_me(3); } +<<<<<<< HEAD fn call_me(num: i32) { +======= +fn call_me(num:) { +>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e for i in 0..num { println!("Ring! Call number {}", i + 1); } diff --git a/exercises/generics/generics2.rs b/exercises/generics/generics2.rs index c2f5a30e..6f7a2612 100644 --- a/exercises/generics/generics2.rs +++ b/exercises/generics/generics2.rs @@ -6,9 +6,17 @@ // Execute `rustlings hint generics2` or use the `hint` watch subcommand for a // hint. +<<<<<<< HEAD struct Wrapper { value: T } +======= +// I AM NOT DONE + +struct Wrapper { + value: u32, +} +>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e impl Wrapper { pub fn new(value: T) -> Self { diff --git a/exercises/if/if1.rs b/exercises/if/if1.rs index 47e13e69..0999ae5c 100644 --- a/exercises/if/if1.rs +++ b/exercises/if/if1.rs @@ -7,12 +7,15 @@ pub fn bigger(a: i32, b: i32) -> i32 { // Do not use: // - another function call // - additional variables +<<<<<<< HEAD // Execute `rustlings hint if1` for hints if (a > b) { return a; } else { return b; } +======= +>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e } // Don't mind this for now :) diff --git a/exercises/if/if2.rs b/exercises/if/if2.rs index 5b33753a..0f1d0e72 100644 --- a/exercises/if/if2.rs +++ b/exercises/if/if2.rs @@ -5,7 +5,13 @@ // // Execute `rustlings hint if2` or use the `hint` watch subcommand for a hint. +<<<<<<< HEAD pub fn fizz_if_foo(fizzish: &str) -> &str { +======= +// I AM NOT DONE + +pub fn foo_if_fizz(fizzish: &str) -> &str { +>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e if fizzish == "fizz" { "foo" } else if fizzish == "fuzz" { diff --git a/exercises/macros/macros4.rs b/exercises/macros/macros4.rs index 5f1ed7e8..e1faab43 100644 --- a/exercises/macros/macros4.rs +++ b/exercises/macros/macros4.rs @@ -3,6 +3,12 @@ // Execute `rustlings hint macros4` or use the `hint` watch subcommand for a // hint. +<<<<<<< HEAD +======= +// I AM NOT DONE + +#[rustfmt::skip] +>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e macro_rules! my_macro { () => { println!("Check out my macro!"); diff --git a/exercises/modules/modules1.rs b/exercises/modules/modules1.rs index 7f2196f1..7365abb9 100644 --- a/exercises/modules/modules1.rs +++ b/exercises/modules/modules1.rs @@ -4,7 +4,17 @@ // hint. mod sausage_factory { +<<<<<<< HEAD pub fn make_sausage() { +======= + // Don't let anybody outside of this module see this! + fn get_secret_recipe() -> String { + String::from("Ginger") + } + + fn make_sausage() { + get_secret_recipe(); +>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e println!("sausage!"); } } diff --git a/exercises/modules/modules2.rs b/exercises/modules/modules2.rs index ad8ecd33..eb8e2581 100644 --- a/exercises/modules/modules2.rs +++ b/exercises/modules/modules2.rs @@ -8,8 +8,14 @@ // hint. mod delicious_snacks { +<<<<<<< HEAD pub use self::fruits::PEAR as fruit; pub use self::veggies::CUCUMBER as veggie; +======= + // TODO: Fix these use statements + use self::fruits::PEAR as ??? + use self::veggies::CUCUMBER as ??? +>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e mod fruits { pub const PEAR: &'static str = "Pear"; diff --git a/exercises/primitive_types/primitive_types2.rs b/exercises/primitive_types/primitive_types2.rs index 1323ae30..97693376 100644 --- a/exercises/primitive_types/primitive_types2.rs +++ b/exercises/primitive_types/primitive_types2.rs @@ -9,7 +9,13 @@ fn main() { // Characters (`char`) +<<<<<<< HEAD let my_first_initial: char = 'C'; +======= + // Note the _single_ quotes, these are different from the double quotes + // you've been seeing around. + let my_first_initial = 'C'; +>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e if my_first_initial.is_alphabetic() { println!("Alphabetical!"); } else if my_first_initial.is_numeric() { diff --git a/exercises/primitive_types/primitive_types6.rs b/exercises/primitive_types/primitive_types6.rs index 8b46312f..583394d9 100644 --- a/exercises/primitive_types/primitive_types6.rs +++ b/exercises/primitive_types/primitive_types6.rs @@ -6,7 +6,20 @@ // Execute `rustlings hint primitive_types6` or use the `hint` watch subcommand // for a hint. +<<<<<<< HEAD fn main() { let numbers = (1, 2, 3); println!("The second number is {}", numbers.1); +======= +// I AM NOT DONE + +#[test] +fn indexing_tuple() { + let numbers = (1, 2, 3); + // Replace below ??? with the tuple indexing syntax. + let second = ???; + + assert_eq!(2, second, + "This is not the 2nd number in the tuple!") +>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e } diff --git a/exercises/quiz3.rs b/exercises/quiz3.rs index 15abd10a..1e5f3439 100644 --- a/exercises/quiz3.rs +++ b/exercises/quiz3.rs @@ -16,8 +16,24 @@ // // Execute `rustlings hint quiz3` or use the `hint` watch subcommand for a hint. +<<<<<<< HEAD pub fn times_two(num: i32) -> i32 { num * 2 +======= +// I AM NOT DONE + +pub struct ReportCard { + pub grade: f32, + pub student_name: String, + pub student_age: u8, +} + +impl ReportCard { + pub fn print(&self) -> String { + format!("{} ({}) - achieved a grade of {}", + &self.student_name, &self.student_age, &self.grade) + } +>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e } #[cfg(test)] @@ -25,6 +41,7 @@ mod tests { use super::*; #[test] +<<<<<<< HEAD fn returns_twice_of_positive_numbers() { assert_eq!(times_two(4), 8); } @@ -33,5 +50,31 @@ mod tests { fn returns_twice_of_negative_numbers() { // TODO write an assert for `times_two(-4)` assert_eq!(times_two(-4), -8); +======= + fn generate_numeric_report_card() { + let report_card = ReportCard { + grade: 2.1, + student_name: "Tom Wriggle".to_string(), + student_age: 12, + }; + assert_eq!( + report_card.print(), + "Tom Wriggle (12) - achieved a grade of 2.1" + ); + } + + #[test] + fn generate_alphabetic_report_card() { + // TODO: Make sure to change the grade here after you finish the exercise. + let report_card = ReportCard { + grade: 2.1, + student_name: "Gary Plotter".to_string(), + student_age: 11, + }; + assert_eq!( + report_card.print(), + "Gary Plotter (11) - achieved a grade of A+" + ); +>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e } } diff --git a/exercises/structs/structs1.rs b/exercises/structs/structs1.rs index 7a03f209..e1801694 100644 --- a/exercises/structs/structs1.rs +++ b/exercises/structs/structs1.rs @@ -45,9 +45,15 @@ mod tests { #[test] fn unit_structs() { +<<<<<<< HEAD // TODO: Instantiate a unit struct! let unit_struct = UnitStruct; let message = format!("{:?}s are fun!", unit_struct); +======= + // TODO: Instantiate a unit-like struct! + // let unit_like_struct = + let message = format!("{:?}s are fun!", unit_like_struct); +>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e assert_eq!(message, "UnitLikeStructs are fun!"); } diff --git a/exercises/structs/structs3.rs b/exercises/structs/structs3.rs index 80fe2b4d..7bdd1717 100644 --- a/exercises/structs/structs3.rs +++ b/exercises/structs/structs3.rs @@ -17,8 +17,12 @@ struct Package { impl Package { fn new(sender_country: String, recipient_country: String, weight_in_grams: i32) -> Package { if weight_in_grams <= 0 { +<<<<<<< HEAD // Something goes here... panic!("Package is lighter then air!") +======= + panic!("Can not ship a weightless package.") +>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e } else { Package { sender_country, @@ -33,9 +37,14 @@ impl Package { self.recipient_country != self.sender_country } +<<<<<<< HEAD fn get_fees(&self, cents_per_kg: i32) -> i32 { // Something goes here... (beware of grams to kg conversion) (self.weight_in_grams * cents_per_kg) / 100 +======= + fn get_fees(&self, cents_per_gram: i32) -> ??? { + // Something goes here... +>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e } } @@ -77,8 +86,13 @@ mod tests { let sender_country = String::from("Spain"); let recipient_country = String::from("Spain"); +<<<<<<< HEAD let cents_per_kg = 300; +======= + let cents_per_gram = 3; + +>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e let package = Package::new(sender_country, recipient_country, 1500); assert_eq!(package.get_fees(cents_per_gram), 4500); diff --git a/exercises/threads/threads1.rs b/exercises/threads/threads1.rs index ea95e9ec..2952930f 100644 --- a/exercises/threads/threads1.rs +++ b/exercises/threads/threads1.rs @@ -1,16 +1,17 @@ // threads1.rs -// -// This program spawns multiple threads that each run for at least 250ms, and -// each thread returns how much time they took to complete. The program should -// wait until all the spawned threads have finished and should collect their -// return values into a vector. -// -// Execute `rustlings hint threads1` or use the `hint` watch subcommand for a -// hint. +// Make this compile! Execute `rustlings hint threads1` for hints :) +// The idea is the thread spawned on line 21 is completing jobs while the main thread is +// monitoring progress until 10 jobs are completed. If you see 6 lines +// of "waiting..." and the program ends without timing out when running, +// you've got it :) use std::sync::{Arc, Mutex}; use std::thread; -use std::time::{Duration, Instant}; +use std::time::Duration; + +struct JobStatus { + jobs_completed: u32, +} fn main() { // Introduce Mutex diff --git a/exercises/traits/traits1.rs b/exercises/traits/traits1.rs index 4ea8c36c..6e00cce9 100644 --- a/exercises/traits/traits1.rs +++ b/exercises/traits/traits1.rs @@ -7,14 +7,23 @@ // Execute `rustlings hint traits1` or use the `hint` watch subcommand for a // hint. +<<<<<<< HEAD +======= +// I AM NOT DONE + +>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e trait AppendBar { fn append_bar(self) -> Self; } impl AppendBar for String { +<<<<<<< HEAD fn append_bar(self) -> Self { self + "Bar" } +======= + // TODO: Implement `AppendBar` for type `String`. +>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e } fn main() { diff --git a/exercises/traits/traits2.rs b/exercises/traits/traits2.rs index eafc2a3e..f9e19186 100644 --- a/exercises/traits/traits2.rs +++ b/exercises/traits/traits2.rs @@ -12,12 +12,16 @@ trait AppendBar { fn append_bar(self) -> Self; } +<<<<<<< HEAD impl AppendBar for Vec { fn append_bar(mut self) -> Self { self.push(String::from("Bar")); self } } +======= +// TODO: Implement trait `AppendBar` for a vector of strings. +>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e #[cfg(test)] mod tests { diff --git a/exercises/variables/variables3.rs b/exercises/variables/variables3.rs index eade4734..aecbbc5f 100644 --- a/exercises/variables/variables3.rs +++ b/exercises/variables/variables3.rs @@ -4,8 +4,12 @@ // hint. fn main() { +<<<<<<< HEAD let mut x = 3; println!("Number {}", x); x = 5; // don't change this line +======= + let x: i32; +>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e println!("Number {}", x); } diff --git a/exercises/variables/variables4.rs b/exercises/variables/variables4.rs index 45434bc7..7da4a366 100644 --- a/exercises/variables/variables4.rs +++ b/exercises/variables/variables4.rs @@ -4,6 +4,12 @@ // hint. fn main() { +<<<<<<< HEAD let x: i32 = 256 * 256 * 256; +======= + let x = 3; + println!("Number {}", x); + x = 5; // don't change this line +>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e println!("Number {}", x); } diff --git a/exercises/variables/variables5.rs b/exercises/variables/variables5.rs index 85281244..df745076 100644 --- a/exercises/variables/variables5.rs +++ b/exercises/variables/variables5.rs @@ -4,8 +4,15 @@ // hint. fn main() { +<<<<<<< HEAD let number = "3"; // don't change this line println!("Number {}", number); let number = 3; println!("Number {}", number); +======= + let number = "T-H-R-E-E"; // don't change this line + println!("Spell a Number : {}", number); + number = 3; // don't rename this variable + println!("Number plus two is : {}", number + 2); +>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e }