Skip to content

add array::FillError similar to array::IntoIter#75717

Closed
lcnr wants to merge 4 commits intorust-lang:masterfrom
lcnr:add-fill-error
Closed

add array::FillError similar to array::IntoIter#75717
lcnr wants to merge 4 commits intorust-lang:masterfrom
lcnr:add-fill-error

Conversation

@lcnr
Copy link
Copy Markdown
Contributor

@lcnr lcnr commented Aug 19, 2020

Taken from #69985 without actually implementing FromIterator so we can merge this without having to worry about
stabilizing anything.

While implementing new methods for arrays, this is very often needed and we otherwise need to reimplement this in each new method.

A huge thanks to @lperlaki, who has done most of the work necessary for this PR as part of #69985.

To summarize, this PR adds struct array::FillError<T, const N: usize>, which is intended as part of the return type of FromIterator for arrays, once we implement this (requires at least stable min_const_generics). The current concept is to implement FromIterator for Result<[T; N], FillError<T, N>>, returning a FillError if the iterator had less than N elements.

Similar to IntoIter, we don't yet actually implement FromIterator but instead add a probably permanently unstable new method to FillError, meaning that one can now write FillError::new().fill(iter).unwrap() to collect into an array, which was previously not cleanly possible.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.