Skip to content
Merged
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
16 changes: 8 additions & 8 deletions exercises/18_iterators/iterators5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn count_for(map: &HashMap<String, Progress>, value: Progress) -> usize {
// of a `for` loop.
fn count_iterator(map: &HashMap<String, Progress>, value: Progress) -> usize {
// `map` is a hash map with `String` keys and `Progress` values.
// map = { "variables1": Complete, "from_str": None, … }
// map = { "variables1": Complete, "conversions3": None, … }
}

fn count_collection_for(collection: &[HashMap<String, Progress>], value: Progress) -> usize {
Expand All @@ -46,7 +46,7 @@ fn count_collection_for(collection: &[HashMap<String, Progress>], value: Progres
// iterator instead of a `for` loop.
fn count_collection_iterator(collection: &[HashMap<String, Progress>], value: Progress) -> usize {
// `collection` is a slice of hash maps.
// collection = [{ "variables1": Complete, "from_str": None, … },
// collection = [{ "variables1": Complete, "conversions3": None, … },
// { "variables2": Complete, … }, … ]
}

Expand All @@ -64,10 +64,10 @@ mod tests {
let mut map = HashMap::new();
map.insert(String::from("variables1"), Complete);
map.insert(String::from("functions1"), Complete);
map.insert(String::from("hashmap1"), Complete);
map.insert(String::from("arc1"), Some);
map.insert(String::from("as_ref_mut"), None);
map.insert(String::from("from_str"), None);
map.insert(String::from("hashmaps1"), Complete);
map.insert(String::from("smart_pointers3"), Some);
map.insert(String::from("conversions5"), None);
map.insert(String::from("conversions3"), None);

map
}
Expand All @@ -81,8 +81,8 @@ mod tests {
other.insert(String::from("variables2"), Complete);
other.insert(String::from("functions2"), Complete);
other.insert(String::from("if1"), Complete);
other.insert(String::from("from_into"), None);
other.insert(String::from("try_from_into"), None);
other.insert(String::from("conversions2"), None);
other.insert(String::from("conversions4"), None);

vec![map, other]
}
Expand Down
11 changes: 6 additions & 5 deletions exercises/23_conversions/conversions3.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// This is similar to the previous `from_into` exercise. But this time, we'll
// implement `FromStr` and return errors instead of falling back to a default
// value. Additionally, upon implementing `FromStr`, you can use the `parse`
// method on strings to generate an object of the implementor type. You can read
// more about it in the documentation:
// In this exercise, we'll implement `FromStr` to convert data stored as a
// string into a structured type. Unlike the `From` trait, the conversion
// expressed by `FromStr` can fail, so it returns a `Result`. Additionally,
// upon implementing `FromStr`, you can use the `parse` method on strings to
// generate an object of the implementor type. You can read more about it in
// the documentation:
// https://doc.rust-lang.org/std/str/trait.FromStr.html

use std::num::ParseIntError;
Expand Down
3 changes: 0 additions & 3 deletions rustlings-macros/info.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1186,9 +1186,6 @@ hint = """
The implementation of `FromStr` should return an `Ok` with a `Person` object,
or an `Err` with an error if the string is not valid.
This is almost like the previous `from_into` exercise, but returning errors
instead of falling back to a default value.
Another hint: You can use the `map_err` method of `Result` with a function or a
closure to wrap the error from `parse::<u8>`.
Expand Down
18 changes: 9 additions & 9 deletions solutions/18_iterators/iterators5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn count_for(map: &HashMap<String, Progress>, value: Progress) -> usize {

fn count_iterator(map: &HashMap<String, Progress>, value: Progress) -> usize {
// `map` is a hash map with `String` keys and `Progress` values.
// map = { "variables1": Complete, "from_str": None, … }
// map = { "variables1": Complete, "conversions3": None, … }
map.values().filter(|val| **val == value).count()
}

Expand All @@ -39,7 +39,7 @@ fn count_collection_for(collection: &[HashMap<String, Progress>], value: Progres

fn count_collection_iterator(collection: &[HashMap<String, Progress>], value: Progress) -> usize {
// `collection` is a slice of hash maps.
// collection = [{ "variables1": Complete, "from_str": None, … },
// collection = [{ "variables1": Complete, "conversions3": None, … },
// { "variables2": Complete, … }, … ]
collection
.iter()
Expand All @@ -55,7 +55,7 @@ fn count_collection_iterator_flat(
value: Progress,
) -> usize {
// `collection` is a slice of hash maps.
// collection = [{ "variables1": Complete, "from_str": None, … },
// collection = [{ "variables1": Complete, "conversions3": None, … },
// { "variables2": Complete, … }, … ]
collection
.iter()
Expand All @@ -77,10 +77,10 @@ mod tests {
let mut map = HashMap::new();
map.insert(String::from("variables1"), Complete);
map.insert(String::from("functions1"), Complete);
map.insert(String::from("hashmap1"), Complete);
map.insert(String::from("arc1"), Some);
map.insert(String::from("as_ref_mut"), None);
map.insert(String::from("from_str"), None);
map.insert(String::from("hashmaps1"), Complete);
map.insert(String::from("smart_pointers3"), Some);
map.insert(String::from("conversions5"), None);
map.insert(String::from("conversions3"), None);

map
}
Expand All @@ -92,8 +92,8 @@ mod tests {
other.insert(String::from("variables2"), Complete);
other.insert(String::from("functions2"), Complete);
other.insert(String::from("if1"), Complete);
other.insert(String::from("from_into"), None);
other.insert(String::from("try_from_into"), None);
other.insert(String::from("conversions2"), None);
other.insert(String::from("conversions4"), None);

vec![map, other]
}
Expand Down
11 changes: 6 additions & 5 deletions solutions/23_conversions/conversions3.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// This is similar to the previous `from_into` exercise. But this time, we'll
// implement `FromStr` and return errors instead of falling back to a default
// value. Additionally, upon implementing `FromStr`, you can use the `parse`
// method on strings to generate an object of the implementor type. You can read
// more about it in the documentation:
// In this exercise, we'll implement `FromStr` to convert data stored as a
// string into a structured type. Unlike the `From` trait, the conversion
// expressed by `FromStr` can fail, so it returns a `Result`. Additionally,
// upon implementing `FromStr`, you can use the `parse` method on strings to
// generate an object of the implementor type. You can read more about it in
// the documentation:
// https://doc.rust-lang.org/std/str/trait.FromStr.html

use std::num::ParseIntError;
Expand Down