try_from_into solution

This commit is contained in:
mo8it
2024-07-02 01:26:09 +02:00
parent e3c8c457ba
commit 5217cdc5e2
3 changed files with 246 additions and 77 deletions
+2 -15
View File
@@ -1197,21 +1197,8 @@ https://doc.rust-lang.org/stable/rust-by-example/error/multiple_error_types/reen
name = "try_from_into"
dir = "23_conversions"
hint = """
Follow the steps provided right before the `TryFrom` implementation.
You can also use the example at
https://doc.rust-lang.org/std/convert/trait.TryFrom.html
Is there an implementation of `TryFrom` in the standard library that
can both do the required integer conversion and check the range of the input?
Another hint: Look at the test cases to see which error variants to return.
Yet another hint: You can use the `map_err` or `or` methods of `Result` to
convert errors.
Yet another hint: If you would like to propagate errors by using the `?`
operator in your solution, you might want to look at
https://doc.rust-lang.org/stable/rust-by-example/error/multiple_error_types/reenter_question_mark.html
Is there an implementation of `TryFrom` in the standard library that can both do
the required integer conversion and check the range of the input?
Challenge: Can you make the `TryFrom` implementations generic over many integer types?"""