Replies: 1 comment
-
interested |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm new to Rust and working through the iterators3 exercise. I encountered some ambiguity regarding the expected return types for the
result_with_list
andlist_of_results
functions.Based on the input (
let numbers = [27, 297, 38502, 81];
) being an array and the format of the desired output comments (// Desired output: Ok([1, 11, 1426, 3]
) and// Desired output: [Ok(1), Ok(11), Ok(1426), Ok(3)])
, I interpreted the task as requiring the functions to return fixed-size arrays rather than dynamically sized Vectors.I came up with the following solutions which pass the tests by returning arrays:
While these solutions work, they feel somewhat "inelegant" because they require manually calling
next().unwrap()
multiple times, rather than using a more idiomatic iterator adapter likecollect()
. I understand thatcollect()
typically targets collections likeVec
, and collecting directly into an array[T; N]
(especiallyResult<[T; N], E>
from an iterator ofResult<T, E>
) isn't straightforward using stable Rust features alone.My Questions:
Is the interpretation that the functions should return fixed-size arrays (
Result<[i64; 4], _>
and[Result<i64, DivisionError>; 4]
) consistent with the intended design of the exercise?If returning arrays is intended, is there a more idiomatic or elegant way to achieve this collection from the iterator within the typical scope of Rustlings exercises (e.g., without nightly features or external crates)?
If the intended solution involves returning
Vec
(e.g.,Result<Vec<i64>, _>
andVec<Result<i64, _>>
), would it be helpful to clarify this expectation in the exercise comments or description? This could prevent confusion for learners who might focus on the array-like syntax in the "Desired output" comments.Beta Was this translation helpful? Give feedback.
All reactions