1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-03-22 06:51:58 +02:00

Adding a link to Solutions from for-loops.md and extending the answer to the bonus questions. (#213)

* Update for-loops.md

* Update solutions-morning.md
This commit is contained in:
Igor Petruk 2023-01-23 11:05:36 +00:00 committed by GitHub
parent 4760295030
commit ec7125da2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -73,3 +73,10 @@ slice-of-slices. Why or why not?
See the [`ndarray` crate](https://docs.rs/ndarray/) for a production quality
implementation.
<details>
The solution and the answer to the bonus section are available in the
[Solution](solutions-morning.md#arrays-and-for-loops) section.
</details>

View File

@ -11,4 +11,6 @@
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<Vec<i32>>`, but this doesn't work very well either: it's hard to convert from `Vec<Vec<i32>>` to `&[&[i32]]` so now you cannot easily use `pretty_print` either.
You can attempt to use something like `Vec<Vec<i32>>`, but this doesn't work very well either: it's hard to convert from `Vec<Vec<i32>>` to `&[&[i32]]` so now you cannot easily use `pretty_print` either.
In addition, the type itself would not enforce that the child slices are of the same length, so such variable could contain an invalid matrix.