1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-04-26 09:12:58 +02:00

for-loop bonus explanation (#108)

* for-loop bonus explanation
This commit is contained in:
鐘天楽 2023-01-06 04:15:16 -05:00 committed by GitHub
parent 9a68434cac
commit c8f626e573
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,3 +7,8 @@
```rust ```rust
{{#include for-loops.rs}} {{#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<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.