Merge pull request #2324 from JatinSanghvi/main

fix: Match solution files with exercise files
This commit is contained in:
Mo Bitar 2025-12-22 14:09:00 +00:00 committed by GitHub
commit 7850a73d95
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 19 additions and 19 deletions

View File

@ -19,7 +19,7 @@ fn main() {
// `.into()` converts a type into an expected type. // `.into()` converts a type into an expected type.
// If it is called where `String` is expected, it will convert `&str` to `String`. // If it is called where `String` is expected, it will convert `&str` to `String`.
string("nice weather".into()); string("nice weather".into());
// But if it is called where `&str` is expected, then `&str` is kept `&str` since no conversion is needed. // But if it is called where `&str` is expected, then `&str` is kept as `&str` since no conversion is needed.
// If you remove the `#[allow(…)]` line, then Clippy will tell you to remove `.into()` below since it is a useless conversion. // If you remove the `#[allow(…)]` line, then Clippy will tell you to remove `.into()` below since it is a useless conversion.
#[allow(clippy::useless_conversion)] #[allow(clippy::useless_conversion)]
string_slice("nice weather".into()); string_slice("nice weather".into());

View File

@ -1,7 +1,7 @@
// A basket of fruits in the form of a hash map needs to be defined. The key // A basket of fruits in the form of a hash map needs to be defined. The key
// represents the name of the fruit and the value represents how many of that // represents the name of the fruit and the value represents how many of that
// particular fruit is in the basket. You have to put at least 3 different // particular fruit is in the basket. You have to put at least 3 different
// types of fruits (e.g apple, banana, mango) in the basket and the total count // types of fruits (e.g. apple, banana, mango) in the basket and the total count
// of all the fruits should be at least 5. // of all the fruits should be at least 5.
use std::collections::HashMap; use std::collections::HashMap;

View File

@ -2,7 +2,7 @@
// If it's before 22:00 (24-hour system), then 5 scoops are left. At 22:00, // If it's before 22:00 (24-hour system), then 5 scoops are left. At 22:00,
// someone eats it all, so no ice cream is left (value 0). Return `None` if // someone eats it all, so no ice cream is left (value 0). Return `None` if
// `hour_of_day` is higher than 23. // `hour_of_day` is higher than 23.
fn maybe_icecream(hour_of_day: u16) -> Option<u16> { fn maybe_ice_cream(hour_of_day: u16) -> Option<u16> {
match hour_of_day { match hour_of_day {
0..=21 => Some(5), 0..=21 => Some(5),
22..=23 => Some(0), 22..=23 => Some(0),
@ -21,19 +21,19 @@ mod tests {
#[test] #[test]
fn raw_value() { fn raw_value() {
// Using `unwrap` is fine in a test. // Using `unwrap` is fine in a test.
let icecreams = maybe_icecream(12).unwrap(); let ice_creams = maybe_ice_cream(12).unwrap();
assert_eq!(icecreams, 5); assert_eq!(ice_creams, 5);
} }
#[test] #[test]
fn check_icecream() { fn check_ice_cream() {
assert_eq!(maybe_icecream(0), Some(5)); assert_eq!(maybe_ice_cream(0), Some(5));
assert_eq!(maybe_icecream(9), Some(5)); assert_eq!(maybe_ice_cream(9), Some(5));
assert_eq!(maybe_icecream(18), Some(5)); assert_eq!(maybe_ice_cream(18), Some(5));
assert_eq!(maybe_icecream(22), Some(0)); assert_eq!(maybe_ice_cream(22), Some(0));
assert_eq!(maybe_icecream(23), Some(0)); assert_eq!(maybe_ice_cream(23), Some(0));
assert_eq!(maybe_icecream(24), None); assert_eq!(maybe_ice_cream(24), None);
assert_eq!(maybe_icecream(25), None); assert_eq!(maybe_ice_cream(25), None);
} }
} }

View File

@ -6,7 +6,7 @@
// //
// In short, this particular use case for boxes is for when you want to own a // In short, this particular use case for boxes is for when you want to own a
// value and you care only that it is a type which implements a particular // value and you care only that it is a type which implements a particular
// trait. To do so, The `Box` is declared as of type `Box<dyn Trait>` where // trait. To do so, the `Box` is declared as of type `Box<dyn Trait>` where
// `Trait` is the trait the compiler looks for on any value used in that // `Trait` is the trait the compiler looks for on any value used in that
// context. For this exercise, that context is the potential errors which // context. For this exercise, that context is the potential errors which
// can be returned in a `Result`. // can be returned in a `Result`.

View File

@ -1,4 +1,4 @@
// Added the attribute `macro_use` attribute. // Added the `macro_use` attribute.
#[macro_use] #[macro_use]
mod macros { mod macros {
macro_rules! my_macro { macro_rules! my_macro {