From c8f626e573a199a12ea92ffc66178dd957aff3be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=90=98=E5=A4=A9=E6=A5=BD?= Date: Fri, 6 Jan 2023 04:15:16 -0500 Subject: [PATCH] for-loop bonus explanation (#108) * for-loop bonus explanation --- src/exercises/day-1/solutions-morning.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/exercises/day-1/solutions-morning.md b/src/exercises/day-1/solutions-morning.md index fce004c7..cd13ad56 100644 --- a/src/exercises/day-1/solutions-morning.md +++ b/src/exercises/day-1/solutions-morning.md @@ -7,3 +7,8 @@ ```rust {{#include for-loops.rs}} ``` +### Bonus question + +It honestly doesn't work so well. It might seem that we could use a slice-of-slices (`&[&[i32]]`) as the input type to transpose and thus make our function handle any size of matrix. However, this quickly breaks down: the return type cannot be `&[&[i32]]` since it needs to own the data you return. + +You can attempt to use something like `Vec>`, but this doesn't work very well either: it's hard to convert from `Vec>` to `&[&[i32]]` so now you cannot easily use `pretty_print` either. \ No newline at end of file