From 2dac8e509bed07c30a98983cfb6b80f73a1582e9 Mon Sep 17 00:00:00 2001 From: mo8it Date: Tue, 23 Apr 2024 19:18:25 +0200 Subject: Refactor embedded files to add solutions --- solutions/23_conversions/from_str.rs | 1 + 1 file changed, 1 insertion(+) create mode 100644 solutions/23_conversions/from_str.rs (limited to 'solutions/23_conversions/from_str.rs') diff --git a/solutions/23_conversions/from_str.rs b/solutions/23_conversions/from_str.rs new file mode 100644 index 0000000..70b786d --- /dev/null +++ b/solutions/23_conversions/from_str.rs @@ -0,0 +1 @@ +// TODO -- cgit v1.2.3 From 177e2870c5272dacee662d3e9522bc57c5a134c0 Mon Sep 17 00:00:00 2001 From: mo8it Date: Thu, 25 Apr 2024 16:30:01 +0200 Subject: Edit comment --- solutions/00_intro/intro1.rs | 2 +- solutions/00_intro/intro2.rs | 2 +- solutions/01_variables/variables1.rs | 2 +- solutions/01_variables/variables2.rs | 2 +- solutions/01_variables/variables3.rs | 2 +- solutions/01_variables/variables4.rs | 2 +- solutions/01_variables/variables5.rs | 2 +- solutions/01_variables/variables6.rs | 2 +- solutions/02_functions/functions1.rs | 2 +- solutions/02_functions/functions2.rs | 2 +- solutions/02_functions/functions3.rs | 2 +- solutions/02_functions/functions4.rs | 2 +- solutions/02_functions/functions5.rs | 2 +- solutions/03_if/if1.rs | 2 +- solutions/03_if/if2.rs | 2 +- solutions/03_if/if3.rs | 2 +- solutions/04_primitive_types/primitive_types1.rs | 2 +- solutions/04_primitive_types/primitive_types2.rs | 2 +- solutions/04_primitive_types/primitive_types3.rs | 2 +- solutions/04_primitive_types/primitive_types4.rs | 2 +- solutions/04_primitive_types/primitive_types5.rs | 2 +- solutions/04_primitive_types/primitive_types6.rs | 2 +- solutions/05_vecs/vecs1.rs | 2 +- solutions/05_vecs/vecs2.rs | 2 +- solutions/06_move_semantics/move_semantics1.rs | 2 +- solutions/06_move_semantics/move_semantics2.rs | 2 +- solutions/06_move_semantics/move_semantics3.rs | 2 +- solutions/06_move_semantics/move_semantics4.rs | 2 +- solutions/06_move_semantics/move_semantics5.rs | 2 +- solutions/06_move_semantics/move_semantics6.rs | 2 +- solutions/07_structs/structs1.rs | 2 +- solutions/07_structs/structs2.rs | 2 +- solutions/07_structs/structs3.rs | 2 +- solutions/08_enums/enums1.rs | 2 +- solutions/08_enums/enums2.rs | 2 +- solutions/08_enums/enums3.rs | 2 +- solutions/09_strings/strings1.rs | 2 +- solutions/09_strings/strings2.rs | 2 +- solutions/09_strings/strings3.rs | 2 +- solutions/09_strings/strings4.rs | 2 +- solutions/10_modules/modules1.rs | 2 +- solutions/10_modules/modules2.rs | 2 +- solutions/10_modules/modules3.rs | 2 +- solutions/11_hashmaps/hashmaps1.rs | 2 +- solutions/11_hashmaps/hashmaps2.rs | 2 +- solutions/11_hashmaps/hashmaps3.rs | 2 +- solutions/12_options/options1.rs | 2 +- solutions/12_options/options2.rs | 2 +- solutions/12_options/options3.rs | 2 +- solutions/13_error_handling/errors1.rs | 2 +- solutions/13_error_handling/errors2.rs | 2 +- solutions/13_error_handling/errors3.rs | 2 +- solutions/13_error_handling/errors4.rs | 2 +- solutions/13_error_handling/errors5.rs | 2 +- solutions/13_error_handling/errors6.rs | 2 +- solutions/14_generics/generics1.rs | 2 +- solutions/14_generics/generics2.rs | 2 +- solutions/15_traits/traits1.rs | 2 +- solutions/15_traits/traits2.rs | 2 +- solutions/15_traits/traits3.rs | 2 +- solutions/15_traits/traits4.rs | 2 +- solutions/15_traits/traits5.rs | 2 +- solutions/16_lifetimes/lifetimes1.rs | 2 +- solutions/16_lifetimes/lifetimes2.rs | 2 +- solutions/16_lifetimes/lifetimes3.rs | 2 +- solutions/17_tests/tests1.rs | 2 +- solutions/17_tests/tests2.rs | 2 +- solutions/17_tests/tests3.rs | 2 +- solutions/17_tests/tests4.rs | 2 +- solutions/18_iterators/iterators1.rs | 2 +- solutions/18_iterators/iterators2.rs | 2 +- solutions/18_iterators/iterators3.rs | 2 +- solutions/18_iterators/iterators4.rs | 2 +- solutions/18_iterators/iterators5.rs | 2 +- solutions/19_smart_pointers/arc1.rs | 2 +- solutions/19_smart_pointers/box1.rs | 2 +- solutions/19_smart_pointers/cow1.rs | 2 +- solutions/19_smart_pointers/rc1.rs | 2 +- solutions/20_threads/threads1.rs | 2 +- solutions/20_threads/threads2.rs | 2 +- solutions/20_threads/threads3.rs | 2 +- solutions/21_macros/macros1.rs | 2 +- solutions/21_macros/macros2.rs | 2 +- solutions/21_macros/macros3.rs | 2 +- solutions/21_macros/macros4.rs | 2 +- solutions/22_clippy/clippy1.rs | 2 +- solutions/22_clippy/clippy2.rs | 2 +- solutions/22_clippy/clippy3.rs | 2 +- solutions/23_conversions/as_ref_mut.rs | 2 +- solutions/23_conversions/from_into.rs | 2 +- solutions/23_conversions/from_str.rs | 2 +- solutions/23_conversions/try_from_into.rs | 2 +- solutions/23_conversions/using_as.rs | 2 +- solutions/quizzes/quiz1.rs | 2 +- solutions/quizzes/quiz2.rs | 2 +- solutions/quizzes/quiz3.rs | 2 +- 96 files changed, 96 insertions(+), 96 deletions(-) (limited to 'solutions/23_conversions/from_str.rs') diff --git a/solutions/00_intro/intro1.rs b/solutions/00_intro/intro1.rs index 70b786d..4e18198 100644 --- a/solutions/00_intro/intro1.rs +++ b/solutions/00_intro/intro1.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/00_intro/intro2.rs b/solutions/00_intro/intro2.rs index 70b786d..4e18198 100644 --- a/solutions/00_intro/intro2.rs +++ b/solutions/00_intro/intro2.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/01_variables/variables1.rs b/solutions/01_variables/variables1.rs index 70b786d..4e18198 100644 --- a/solutions/01_variables/variables1.rs +++ b/solutions/01_variables/variables1.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/01_variables/variables2.rs b/solutions/01_variables/variables2.rs index 70b786d..4e18198 100644 --- a/solutions/01_variables/variables2.rs +++ b/solutions/01_variables/variables2.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/01_variables/variables3.rs b/solutions/01_variables/variables3.rs index 70b786d..4e18198 100644 --- a/solutions/01_variables/variables3.rs +++ b/solutions/01_variables/variables3.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/01_variables/variables4.rs b/solutions/01_variables/variables4.rs index 70b786d..4e18198 100644 --- a/solutions/01_variables/variables4.rs +++ b/solutions/01_variables/variables4.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/01_variables/variables5.rs b/solutions/01_variables/variables5.rs index 70b786d..4e18198 100644 --- a/solutions/01_variables/variables5.rs +++ b/solutions/01_variables/variables5.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/01_variables/variables6.rs b/solutions/01_variables/variables6.rs index 70b786d..4e18198 100644 --- a/solutions/01_variables/variables6.rs +++ b/solutions/01_variables/variables6.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/02_functions/functions1.rs b/solutions/02_functions/functions1.rs index 70b786d..4e18198 100644 --- a/solutions/02_functions/functions1.rs +++ b/solutions/02_functions/functions1.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/02_functions/functions2.rs b/solutions/02_functions/functions2.rs index 70b786d..4e18198 100644 --- a/solutions/02_functions/functions2.rs +++ b/solutions/02_functions/functions2.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/02_functions/functions3.rs b/solutions/02_functions/functions3.rs index 70b786d..4e18198 100644 --- a/solutions/02_functions/functions3.rs +++ b/solutions/02_functions/functions3.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/02_functions/functions4.rs b/solutions/02_functions/functions4.rs index 70b786d..4e18198 100644 --- a/solutions/02_functions/functions4.rs +++ b/solutions/02_functions/functions4.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/02_functions/functions5.rs b/solutions/02_functions/functions5.rs index 70b786d..4e18198 100644 --- a/solutions/02_functions/functions5.rs +++ b/solutions/02_functions/functions5.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/03_if/if1.rs b/solutions/03_if/if1.rs index 70b786d..4e18198 100644 --- a/solutions/03_if/if1.rs +++ b/solutions/03_if/if1.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/03_if/if2.rs b/solutions/03_if/if2.rs index 70b786d..4e18198 100644 --- a/solutions/03_if/if2.rs +++ b/solutions/03_if/if2.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/03_if/if3.rs b/solutions/03_if/if3.rs index 70b786d..4e18198 100644 --- a/solutions/03_if/if3.rs +++ b/solutions/03_if/if3.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/04_primitive_types/primitive_types1.rs b/solutions/04_primitive_types/primitive_types1.rs index 70b786d..4e18198 100644 --- a/solutions/04_primitive_types/primitive_types1.rs +++ b/solutions/04_primitive_types/primitive_types1.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/04_primitive_types/primitive_types2.rs b/solutions/04_primitive_types/primitive_types2.rs index 70b786d..4e18198 100644 --- a/solutions/04_primitive_types/primitive_types2.rs +++ b/solutions/04_primitive_types/primitive_types2.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/04_primitive_types/primitive_types3.rs b/solutions/04_primitive_types/primitive_types3.rs index 70b786d..4e18198 100644 --- a/solutions/04_primitive_types/primitive_types3.rs +++ b/solutions/04_primitive_types/primitive_types3.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/04_primitive_types/primitive_types4.rs b/solutions/04_primitive_types/primitive_types4.rs index 70b786d..4e18198 100644 --- a/solutions/04_primitive_types/primitive_types4.rs +++ b/solutions/04_primitive_types/primitive_types4.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/04_primitive_types/primitive_types5.rs b/solutions/04_primitive_types/primitive_types5.rs index 70b786d..4e18198 100644 --- a/solutions/04_primitive_types/primitive_types5.rs +++ b/solutions/04_primitive_types/primitive_types5.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/04_primitive_types/primitive_types6.rs b/solutions/04_primitive_types/primitive_types6.rs index 70b786d..4e18198 100644 --- a/solutions/04_primitive_types/primitive_types6.rs +++ b/solutions/04_primitive_types/primitive_types6.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/05_vecs/vecs1.rs b/solutions/05_vecs/vecs1.rs index 70b786d..4e18198 100644 --- a/solutions/05_vecs/vecs1.rs +++ b/solutions/05_vecs/vecs1.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/05_vecs/vecs2.rs b/solutions/05_vecs/vecs2.rs index 70b786d..4e18198 100644 --- a/solutions/05_vecs/vecs2.rs +++ b/solutions/05_vecs/vecs2.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/06_move_semantics/move_semantics1.rs b/solutions/06_move_semantics/move_semantics1.rs index 70b786d..4e18198 100644 --- a/solutions/06_move_semantics/move_semantics1.rs +++ b/solutions/06_move_semantics/move_semantics1.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/06_move_semantics/move_semantics2.rs b/solutions/06_move_semantics/move_semantics2.rs index 70b786d..4e18198 100644 --- a/solutions/06_move_semantics/move_semantics2.rs +++ b/solutions/06_move_semantics/move_semantics2.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/06_move_semantics/move_semantics3.rs b/solutions/06_move_semantics/move_semantics3.rs index 70b786d..4e18198 100644 --- a/solutions/06_move_semantics/move_semantics3.rs +++ b/solutions/06_move_semantics/move_semantics3.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/06_move_semantics/move_semantics4.rs b/solutions/06_move_semantics/move_semantics4.rs index 70b786d..4e18198 100644 --- a/solutions/06_move_semantics/move_semantics4.rs +++ b/solutions/06_move_semantics/move_semantics4.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/06_move_semantics/move_semantics5.rs b/solutions/06_move_semantics/move_semantics5.rs index 70b786d..4e18198 100644 --- a/solutions/06_move_semantics/move_semantics5.rs +++ b/solutions/06_move_semantics/move_semantics5.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/06_move_semantics/move_semantics6.rs b/solutions/06_move_semantics/move_semantics6.rs index 70b786d..4e18198 100644 --- a/solutions/06_move_semantics/move_semantics6.rs +++ b/solutions/06_move_semantics/move_semantics6.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/07_structs/structs1.rs b/solutions/07_structs/structs1.rs index 70b786d..4e18198 100644 --- a/solutions/07_structs/structs1.rs +++ b/solutions/07_structs/structs1.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/07_structs/structs2.rs b/solutions/07_structs/structs2.rs index 70b786d..4e18198 100644 --- a/solutions/07_structs/structs2.rs +++ b/solutions/07_structs/structs2.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/07_structs/structs3.rs b/solutions/07_structs/structs3.rs index 70b786d..4e18198 100644 --- a/solutions/07_structs/structs3.rs +++ b/solutions/07_structs/structs3.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/08_enums/enums1.rs b/solutions/08_enums/enums1.rs index 70b786d..4e18198 100644 --- a/solutions/08_enums/enums1.rs +++ b/solutions/08_enums/enums1.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/08_enums/enums2.rs b/solutions/08_enums/enums2.rs index 70b786d..4e18198 100644 --- a/solutions/08_enums/enums2.rs +++ b/solutions/08_enums/enums2.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/08_enums/enums3.rs b/solutions/08_enums/enums3.rs index 70b786d..4e18198 100644 --- a/solutions/08_enums/enums3.rs +++ b/solutions/08_enums/enums3.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/09_strings/strings1.rs b/solutions/09_strings/strings1.rs index 70b786d..4e18198 100644 --- a/solutions/09_strings/strings1.rs +++ b/solutions/09_strings/strings1.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/09_strings/strings2.rs b/solutions/09_strings/strings2.rs index 70b786d..4e18198 100644 --- a/solutions/09_strings/strings2.rs +++ b/solutions/09_strings/strings2.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/09_strings/strings3.rs b/solutions/09_strings/strings3.rs index 70b786d..4e18198 100644 --- a/solutions/09_strings/strings3.rs +++ b/solutions/09_strings/strings3.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/09_strings/strings4.rs b/solutions/09_strings/strings4.rs index 70b786d..4e18198 100644 --- a/solutions/09_strings/strings4.rs +++ b/solutions/09_strings/strings4.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/10_modules/modules1.rs b/solutions/10_modules/modules1.rs index 70b786d..4e18198 100644 --- a/solutions/10_modules/modules1.rs +++ b/solutions/10_modules/modules1.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/10_modules/modules2.rs b/solutions/10_modules/modules2.rs index 70b786d..4e18198 100644 --- a/solutions/10_modules/modules2.rs +++ b/solutions/10_modules/modules2.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/10_modules/modules3.rs b/solutions/10_modules/modules3.rs index 70b786d..4e18198 100644 --- a/solutions/10_modules/modules3.rs +++ b/solutions/10_modules/modules3.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/11_hashmaps/hashmaps1.rs b/solutions/11_hashmaps/hashmaps1.rs index 70b786d..4e18198 100644 --- a/solutions/11_hashmaps/hashmaps1.rs +++ b/solutions/11_hashmaps/hashmaps1.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/11_hashmaps/hashmaps2.rs b/solutions/11_hashmaps/hashmaps2.rs index 70b786d..4e18198 100644 --- a/solutions/11_hashmaps/hashmaps2.rs +++ b/solutions/11_hashmaps/hashmaps2.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/11_hashmaps/hashmaps3.rs b/solutions/11_hashmaps/hashmaps3.rs index 70b786d..4e18198 100644 --- a/solutions/11_hashmaps/hashmaps3.rs +++ b/solutions/11_hashmaps/hashmaps3.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/12_options/options1.rs b/solutions/12_options/options1.rs index 70b786d..4e18198 100644 --- a/solutions/12_options/options1.rs +++ b/solutions/12_options/options1.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/12_options/options2.rs b/solutions/12_options/options2.rs index 70b786d..4e18198 100644 --- a/solutions/12_options/options2.rs +++ b/solutions/12_options/options2.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/12_options/options3.rs b/solutions/12_options/options3.rs index 70b786d..4e18198 100644 --- a/solutions/12_options/options3.rs +++ b/solutions/12_options/options3.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/13_error_handling/errors1.rs b/solutions/13_error_handling/errors1.rs index 70b786d..4e18198 100644 --- a/solutions/13_error_handling/errors1.rs +++ b/solutions/13_error_handling/errors1.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/13_error_handling/errors2.rs b/solutions/13_error_handling/errors2.rs index 70b786d..4e18198 100644 --- a/solutions/13_error_handling/errors2.rs +++ b/solutions/13_error_handling/errors2.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/13_error_handling/errors3.rs b/solutions/13_error_handling/errors3.rs index 70b786d..4e18198 100644 --- a/solutions/13_error_handling/errors3.rs +++ b/solutions/13_error_handling/errors3.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/13_error_handling/errors4.rs b/solutions/13_error_handling/errors4.rs index 70b786d..4e18198 100644 --- a/solutions/13_error_handling/errors4.rs +++ b/solutions/13_error_handling/errors4.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/13_error_handling/errors5.rs b/solutions/13_error_handling/errors5.rs index 70b786d..4e18198 100644 --- a/solutions/13_error_handling/errors5.rs +++ b/solutions/13_error_handling/errors5.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/13_error_handling/errors6.rs b/solutions/13_error_handling/errors6.rs index 70b786d..4e18198 100644 --- a/solutions/13_error_handling/errors6.rs +++ b/solutions/13_error_handling/errors6.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/14_generics/generics1.rs b/solutions/14_generics/generics1.rs index 70b786d..4e18198 100644 --- a/solutions/14_generics/generics1.rs +++ b/solutions/14_generics/generics1.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/14_generics/generics2.rs b/solutions/14_generics/generics2.rs index 70b786d..4e18198 100644 --- a/solutions/14_generics/generics2.rs +++ b/solutions/14_generics/generics2.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/15_traits/traits1.rs b/solutions/15_traits/traits1.rs index 70b786d..4e18198 100644 --- a/solutions/15_traits/traits1.rs +++ b/solutions/15_traits/traits1.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/15_traits/traits2.rs b/solutions/15_traits/traits2.rs index 70b786d..4e18198 100644 --- a/solutions/15_traits/traits2.rs +++ b/solutions/15_traits/traits2.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/15_traits/traits3.rs b/solutions/15_traits/traits3.rs index 70b786d..4e18198 100644 --- a/solutions/15_traits/traits3.rs +++ b/solutions/15_traits/traits3.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/15_traits/traits4.rs b/solutions/15_traits/traits4.rs index 70b786d..4e18198 100644 --- a/solutions/15_traits/traits4.rs +++ b/solutions/15_traits/traits4.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/15_traits/traits5.rs b/solutions/15_traits/traits5.rs index 70b786d..4e18198 100644 --- a/solutions/15_traits/traits5.rs +++ b/solutions/15_traits/traits5.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/16_lifetimes/lifetimes1.rs b/solutions/16_lifetimes/lifetimes1.rs index 70b786d..4e18198 100644 --- a/solutions/16_lifetimes/lifetimes1.rs +++ b/solutions/16_lifetimes/lifetimes1.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/16_lifetimes/lifetimes2.rs b/solutions/16_lifetimes/lifetimes2.rs index 70b786d..4e18198 100644 --- a/solutions/16_lifetimes/lifetimes2.rs +++ b/solutions/16_lifetimes/lifetimes2.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/16_lifetimes/lifetimes3.rs b/solutions/16_lifetimes/lifetimes3.rs index 70b786d..4e18198 100644 --- a/solutions/16_lifetimes/lifetimes3.rs +++ b/solutions/16_lifetimes/lifetimes3.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/17_tests/tests1.rs b/solutions/17_tests/tests1.rs index 70b786d..4e18198 100644 --- a/solutions/17_tests/tests1.rs +++ b/solutions/17_tests/tests1.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/17_tests/tests2.rs b/solutions/17_tests/tests2.rs index 70b786d..4e18198 100644 --- a/solutions/17_tests/tests2.rs +++ b/solutions/17_tests/tests2.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/17_tests/tests3.rs b/solutions/17_tests/tests3.rs index 70b786d..4e18198 100644 --- a/solutions/17_tests/tests3.rs +++ b/solutions/17_tests/tests3.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/17_tests/tests4.rs b/solutions/17_tests/tests4.rs index 70b786d..4e18198 100644 --- a/solutions/17_tests/tests4.rs +++ b/solutions/17_tests/tests4.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/18_iterators/iterators1.rs b/solutions/18_iterators/iterators1.rs index 70b786d..4e18198 100644 --- a/solutions/18_iterators/iterators1.rs +++ b/solutions/18_iterators/iterators1.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/18_iterators/iterators2.rs b/solutions/18_iterators/iterators2.rs index 70b786d..4e18198 100644 --- a/solutions/18_iterators/iterators2.rs +++ b/solutions/18_iterators/iterators2.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/18_iterators/iterators3.rs b/solutions/18_iterators/iterators3.rs index 70b786d..4e18198 100644 --- a/solutions/18_iterators/iterators3.rs +++ b/solutions/18_iterators/iterators3.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/18_iterators/iterators4.rs b/solutions/18_iterators/iterators4.rs index 70b786d..4e18198 100644 --- a/solutions/18_iterators/iterators4.rs +++ b/solutions/18_iterators/iterators4.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/18_iterators/iterators5.rs b/solutions/18_iterators/iterators5.rs index 70b786d..4e18198 100644 --- a/solutions/18_iterators/iterators5.rs +++ b/solutions/18_iterators/iterators5.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/19_smart_pointers/arc1.rs b/solutions/19_smart_pointers/arc1.rs index 70b786d..4e18198 100644 --- a/solutions/19_smart_pointers/arc1.rs +++ b/solutions/19_smart_pointers/arc1.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/19_smart_pointers/box1.rs b/solutions/19_smart_pointers/box1.rs index 70b786d..4e18198 100644 --- a/solutions/19_smart_pointers/box1.rs +++ b/solutions/19_smart_pointers/box1.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/19_smart_pointers/cow1.rs b/solutions/19_smart_pointers/cow1.rs index 70b786d..4e18198 100644 --- a/solutions/19_smart_pointers/cow1.rs +++ b/solutions/19_smart_pointers/cow1.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/19_smart_pointers/rc1.rs b/solutions/19_smart_pointers/rc1.rs index 70b786d..4e18198 100644 --- a/solutions/19_smart_pointers/rc1.rs +++ b/solutions/19_smart_pointers/rc1.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/20_threads/threads1.rs b/solutions/20_threads/threads1.rs index 70b786d..4e18198 100644 --- a/solutions/20_threads/threads1.rs +++ b/solutions/20_threads/threads1.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/20_threads/threads2.rs b/solutions/20_threads/threads2.rs index 70b786d..4e18198 100644 --- a/solutions/20_threads/threads2.rs +++ b/solutions/20_threads/threads2.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/20_threads/threads3.rs b/solutions/20_threads/threads3.rs index 70b786d..4e18198 100644 --- a/solutions/20_threads/threads3.rs +++ b/solutions/20_threads/threads3.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/21_macros/macros1.rs b/solutions/21_macros/macros1.rs index 70b786d..4e18198 100644 --- a/solutions/21_macros/macros1.rs +++ b/solutions/21_macros/macros1.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/21_macros/macros2.rs b/solutions/21_macros/macros2.rs index 70b786d..4e18198 100644 --- a/solutions/21_macros/macros2.rs +++ b/solutions/21_macros/macros2.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/21_macros/macros3.rs b/solutions/21_macros/macros3.rs index 70b786d..4e18198 100644 --- a/solutions/21_macros/macros3.rs +++ b/solutions/21_macros/macros3.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/21_macros/macros4.rs b/solutions/21_macros/macros4.rs index 70b786d..4e18198 100644 --- a/solutions/21_macros/macros4.rs +++ b/solutions/21_macros/macros4.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/22_clippy/clippy1.rs b/solutions/22_clippy/clippy1.rs index 70b786d..4e18198 100644 --- a/solutions/22_clippy/clippy1.rs +++ b/solutions/22_clippy/clippy1.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/22_clippy/clippy2.rs b/solutions/22_clippy/clippy2.rs index 70b786d..4e18198 100644 --- a/solutions/22_clippy/clippy2.rs +++ b/solutions/22_clippy/clippy2.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/22_clippy/clippy3.rs b/solutions/22_clippy/clippy3.rs index 70b786d..4e18198 100644 --- a/solutions/22_clippy/clippy3.rs +++ b/solutions/22_clippy/clippy3.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/23_conversions/as_ref_mut.rs b/solutions/23_conversions/as_ref_mut.rs index 70b786d..4e18198 100644 --- a/solutions/23_conversions/as_ref_mut.rs +++ b/solutions/23_conversions/as_ref_mut.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/23_conversions/from_into.rs b/solutions/23_conversions/from_into.rs index 70b786d..4e18198 100644 --- a/solutions/23_conversions/from_into.rs +++ b/solutions/23_conversions/from_into.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/23_conversions/from_str.rs b/solutions/23_conversions/from_str.rs index 70b786d..4e18198 100644 --- a/solutions/23_conversions/from_str.rs +++ b/solutions/23_conversions/from_str.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/23_conversions/try_from_into.rs b/solutions/23_conversions/try_from_into.rs index 70b786d..4e18198 100644 --- a/solutions/23_conversions/try_from_into.rs +++ b/solutions/23_conversions/try_from_into.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/23_conversions/using_as.rs b/solutions/23_conversions/using_as.rs index 70b786d..4e18198 100644 --- a/solutions/23_conversions/using_as.rs +++ b/solutions/23_conversions/using_as.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/quizzes/quiz1.rs b/solutions/quizzes/quiz1.rs index 70b786d..4e18198 100644 --- a/solutions/quizzes/quiz1.rs +++ b/solutions/quizzes/quiz1.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/quizzes/quiz2.rs b/solutions/quizzes/quiz2.rs index 70b786d..4e18198 100644 --- a/solutions/quizzes/quiz2.rs +++ b/solutions/quizzes/quiz2.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 diff --git a/solutions/quizzes/quiz3.rs b/solutions/quizzes/quiz3.rs index 70b786d..4e18198 100644 --- a/solutions/quizzes/quiz3.rs +++ b/solutions/quizzes/quiz3.rs @@ -1 +1 @@ -// TODO +// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 -- cgit v1.2.3 From e3c8c457ba8744b0f1b799c4d7d4bf24e8e61792 Mon Sep 17 00:00:00 2001 From: mo8it Date: Tue, 2 Jul 2024 01:03:55 +0200 Subject: from_str solution --- exercises/23_conversions/from_str.rs | 60 ++++++++-------- rustlings-macros/info.toml | 10 ++- solutions/23_conversions/from_str.rs | 129 ++++++++++++++++++++++++++++++++++- 3 files changed, 163 insertions(+), 36 deletions(-) (limited to 'solutions/23_conversions/from_str.rs') diff --git a/exercises/23_conversions/from_str.rs b/exercises/23_conversions/from_str.rs index 58270f0..1b3f553 100644 --- a/exercises/23_conversions/from_str.rs +++ b/exercises/23_conversions/from_str.rs @@ -1,7 +1,8 @@ -// This is similar to from_into.rs, 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 at +// 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: // https://doc.rust-lang.org/std/str/trait.FromStr.html use std::num::ParseIntError; @@ -10,43 +11,42 @@ use std::str::FromStr; #[derive(Debug, PartialEq)] struct Person { name: String, - age: usize, + age: u8, } // We will use this error type for the `FromStr` implementation. #[derive(Debug, PartialEq)] enum ParsePersonError { - // Empty input string - Empty, // Incorrect number of fields BadLen, // Empty name field NoName, - // Wrapped error from parse::() + // Wrapped error from parse::() ParseInt(ParseIntError), } +// TODO: Complete this `From` implementation to be able to parse a `Person` +// out of a string in the form of "Mark,20". +// Note that you'll need to parse the age component into a `u8` with something +// like `"4".parse::()`. +// // Steps: -// 1. If the length of the provided string is 0, an error should be returned -// 2. Split the given string on the commas present in it -// 3. Only 2 elements should be returned from the split, otherwise return an -// error -// 4. Extract the first element from the split operation and use it as the name -// 5. Extract the other element from the split operation and parse it into a -// `usize` as the age with something like `"4".parse::()` -// 6. If while extracting the name and the age something goes wrong, an error -// should be returned -// If everything goes well, then return a Result of a Person object - +// 1. Split the given string on the commas present in it. +// 2. If the split operation returns less or more than 2 elements, return the +// error `ParsePersonError::BadLen`. +// 3. Use the first element from the split operation as the name. +// 4. If the name is empty, return the error `ParsePersonError::NoName`. +// 5. Parse the second element from the split operation into a `u8` as the age. +// 6. If parsing the age fails, return the error `ParsePersonError::ParseInt`. impl FromStr for Person { type Err = ParsePersonError; - fn from_str(s: &str) -> Result { - } + + fn from_str(s: &str) -> Result {} } fn main() { - let p = "Mark,20".parse::().unwrap(); - println!("{:?}", p); + let p = "Mark,20".parse::(); + println!("{p:?}"); } #[cfg(test)] @@ -55,8 +55,9 @@ mod tests { #[test] fn empty_input() { - assert_eq!("".parse::(), Err(ParsePersonError::Empty)); + assert_eq!("".parse::(), Err(ParsePersonError::BadLen)); } + #[test] fn good_input() { let p = "John,32".parse::(); @@ -65,11 +66,12 @@ mod tests { assert_eq!(p.name, "John"); assert_eq!(p.age, 32); } + #[test] fn missing_age() { assert!(matches!( "John,".parse::(), - Err(ParsePersonError::ParseInt(_)) + Err(ParsePersonError::ParseInt(_)), )); } @@ -77,7 +79,7 @@ mod tests { fn invalid_age() { assert!(matches!( "John,twenty".parse::(), - Err(ParsePersonError::ParseInt(_)) + Err(ParsePersonError::ParseInt(_)), )); } @@ -95,7 +97,7 @@ mod tests { fn missing_name_and_age() { assert!(matches!( ",".parse::(), - Err(ParsePersonError::NoName | ParsePersonError::ParseInt(_)) + Err(ParsePersonError::NoName | ParsePersonError::ParseInt(_)), )); } @@ -103,7 +105,7 @@ mod tests { fn missing_name_and_invalid_age() { assert!(matches!( ",one".parse::(), - Err(ParsePersonError::NoName | ParsePersonError::ParseInt(_)) + Err(ParsePersonError::NoName | ParsePersonError::ParseInt(_)), )); } @@ -116,7 +118,7 @@ mod tests { fn trailing_comma_and_some_string() { assert_eq!( "John,32,man".parse::(), - Err(ParsePersonError::BadLen) + Err(ParsePersonError::BadLen), ); } } diff --git a/rustlings-macros/info.toml b/rustlings-macros/info.toml index b848e0e..4ef1a0a 100644 --- a/rustlings-macros/info.toml +++ b/rustlings-macros/info.toml @@ -1183,13 +1183,11 @@ 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 `from_into` exercise, but returning errors instead -of falling back to a default value. +This is almost like the previous `from_into` exercise, but returning errors +instead of falling back to a default value. -Look at the test cases to see which error variants to return. - -Another hint: You can use the `map_err` method of `Result` with a function -or a closure to wrap the error from `parse::`. +Another hint: You can use the `map_err` method of `Result` with a function or a +closure to wrap the error from `parse::`. Yet another hint: If you would like to propagate errors by using the `?` operator in your solution, you might want to look at diff --git a/solutions/23_conversions/from_str.rs b/solutions/23_conversions/from_str.rs index 4e18198..301150b 100644 --- a/solutions/23_conversions/from_str.rs +++ b/solutions/23_conversions/from_str.rs @@ -1 +1,128 @@ -// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 +// 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: +// https://doc.rust-lang.org/std/str/trait.FromStr.html + +use std::num::ParseIntError; +use std::str::FromStr; + +#[derive(Debug, PartialEq)] +struct Person { + name: String, + age: u8, +} + +// We will use this error type for the `FromStr` implementation. +#[derive(Debug, PartialEq)] +enum ParsePersonError { + // Incorrect number of fields + BadLen, + // Empty name field + NoName, + // Wrapped error from parse::() + ParseInt(ParseIntError), +} + +impl FromStr for Person { + type Err = ParsePersonError; + + fn from_str(s: &str) -> Result { + let mut split = s.split(','); + let (Some(name), Some(age), None) = (split.next(), split.next(), split.next()) else { + // ^^^^ there should be no third element + return Err(ParsePersonError::BadLen); + }; + + if name.is_empty() { + return Err(ParsePersonError::NoName); + } + + let age = age.parse().map_err(ParsePersonError::ParseInt)?; + + Ok(Self { + name: name.into(), + age, + }) + } +} + +fn main() { + let p = "Mark,20".parse::(); + println!("{p:?}"); +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn empty_input() { + assert_eq!("".parse::(), Err(ParsePersonError::BadLen)); + } + + #[test] + fn good_input() { + let p = "John,32".parse::(); + assert!(p.is_ok()); + let p = p.unwrap(); + assert_eq!(p.name, "John"); + assert_eq!(p.age, 32); + } + + #[test] + fn missing_age() { + assert!(matches!( + "John,".parse::(), + Err(ParsePersonError::ParseInt(_)), + )); + } + + #[test] + fn invalid_age() { + assert!(matches!( + "John,twenty".parse::(), + Err(ParsePersonError::ParseInt(_)), + )); + } + + #[test] + fn missing_comma_and_age() { + assert_eq!("John".parse::(), Err(ParsePersonError::BadLen)); + } + + #[test] + fn missing_name() { + assert_eq!(",1".parse::(), Err(ParsePersonError::NoName)); + } + + #[test] + fn missing_name_and_age() { + assert!(matches!( + ",".parse::(), + Err(ParsePersonError::NoName | ParsePersonError::ParseInt(_)), + )); + } + + #[test] + fn missing_name_and_invalid_age() { + assert!(matches!( + ",one".parse::(), + Err(ParsePersonError::NoName | ParsePersonError::ParseInt(_)), + )); + } + + #[test] + fn trailing_comma() { + assert_eq!("John,32,".parse::(), Err(ParsePersonError::BadLen)); + } + + #[test] + fn trailing_comma_and_some_string() { + assert_eq!( + "John,32,man".parse::(), + Err(ParsePersonError::BadLen), + ); + } +} -- cgit v1.2.3 From 8ef5d10da2252ec270b9170af25dabc466113e99 Mon Sep 17 00:00:00 2001 From: mo8it Date: Tue, 2 Jul 2024 01:29:30 +0200 Subject: Import the error variants in the tests --- exercises/23_conversions/from_str.rs | 31 ++++++++++--------------------- solutions/23_conversions/from_str.rs | 31 ++++++++++--------------------- 2 files changed, 20 insertions(+), 42 deletions(-) (limited to 'solutions/23_conversions/from_str.rs') diff --git a/exercises/23_conversions/from_str.rs b/exercises/23_conversions/from_str.rs index 1b3f553..4b1aaa2 100644 --- a/exercises/23_conversions/from_str.rs +++ b/exercises/23_conversions/from_str.rs @@ -52,10 +52,11 @@ fn main() { #[cfg(test)] mod tests { use super::*; + use ParsePersonError::*; #[test] fn empty_input() { - assert_eq!("".parse::(), Err(ParsePersonError::BadLen)); + assert_eq!("".parse::(), Err(BadLen)); } #[test] @@ -69,56 +70,44 @@ mod tests { #[test] fn missing_age() { - assert!(matches!( - "John,".parse::(), - Err(ParsePersonError::ParseInt(_)), - )); + assert!(matches!("John,".parse::(), Err(ParseInt(_)))); } #[test] fn invalid_age() { - assert!(matches!( - "John,twenty".parse::(), - Err(ParsePersonError::ParseInt(_)), - )); + assert!(matches!("John,twenty".parse::(), Err(ParseInt(_)))); } #[test] fn missing_comma_and_age() { - assert_eq!("John".parse::(), Err(ParsePersonError::BadLen)); + assert_eq!("John".parse::(), Err(BadLen)); } #[test] fn missing_name() { - assert_eq!(",1".parse::(), Err(ParsePersonError::NoName)); + assert_eq!(",1".parse::(), Err(NoName)); } #[test] fn missing_name_and_age() { - assert!(matches!( - ",".parse::(), - Err(ParsePersonError::NoName | ParsePersonError::ParseInt(_)), - )); + assert!(matches!(",".parse::(), Err(NoName | ParseInt(_)))); } #[test] fn missing_name_and_invalid_age() { assert!(matches!( ",one".parse::(), - Err(ParsePersonError::NoName | ParsePersonError::ParseInt(_)), + Err(NoName | ParseInt(_)), )); } #[test] fn trailing_comma() { - assert_eq!("John,32,".parse::(), Err(ParsePersonError::BadLen)); + assert_eq!("John,32,".parse::(), Err(BadLen)); } #[test] fn trailing_comma_and_some_string() { - assert_eq!( - "John,32,man".parse::(), - Err(ParsePersonError::BadLen), - ); + assert_eq!("John,32,man".parse::(), Err(BadLen)); } } diff --git a/solutions/23_conversions/from_str.rs b/solutions/23_conversions/from_str.rs index 301150b..005b501 100644 --- a/solutions/23_conversions/from_str.rs +++ b/solutions/23_conversions/from_str.rs @@ -56,10 +56,11 @@ fn main() { #[cfg(test)] mod tests { use super::*; + use ParsePersonError::*; #[test] fn empty_input() { - assert_eq!("".parse::(), Err(ParsePersonError::BadLen)); + assert_eq!("".parse::(), Err(BadLen)); } #[test] @@ -73,56 +74,44 @@ mod tests { #[test] fn missing_age() { - assert!(matches!( - "John,".parse::(), - Err(ParsePersonError::ParseInt(_)), - )); + assert!(matches!("John,".parse::(), Err(ParseInt(_)))); } #[test] fn invalid_age() { - assert!(matches!( - "John,twenty".parse::(), - Err(ParsePersonError::ParseInt(_)), - )); + assert!(matches!("John,twenty".parse::(), Err(ParseInt(_)))); } #[test] fn missing_comma_and_age() { - assert_eq!("John".parse::(), Err(ParsePersonError::BadLen)); + assert_eq!("John".parse::(), Err(BadLen)); } #[test] fn missing_name() { - assert_eq!(",1".parse::(), Err(ParsePersonError::NoName)); + assert_eq!(",1".parse::(), Err(NoName)); } #[test] fn missing_name_and_age() { - assert!(matches!( - ",".parse::(), - Err(ParsePersonError::NoName | ParsePersonError::ParseInt(_)), - )); + assert!(matches!(",".parse::(), Err(NoName | ParseInt(_)))); } #[test] fn missing_name_and_invalid_age() { assert!(matches!( ",one".parse::(), - Err(ParsePersonError::NoName | ParsePersonError::ParseInt(_)), + Err(NoName | ParseInt(_)), )); } #[test] fn trailing_comma() { - assert_eq!("John,32,".parse::(), Err(ParsePersonError::BadLen)); + assert_eq!("John,32,".parse::(), Err(BadLen)); } #[test] fn trailing_comma_and_some_string() { - assert_eq!( - "John,32,man".parse::(), - Err(ParsePersonError::BadLen), - ); + assert_eq!("John,32,man".parse::(), Err(BadLen)); } } -- cgit v1.2.3