-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add array::FillError
similar to array::IntoIter
#75717
Conversation
r? @kennytm (rust_highfive has picked a reviewer for you, use r? to override) |
|
Potentially, I am not sure if we want I wouldn't panic if there aren't too many items but just silently ignore the rest. As Opened https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/.60ArrayVec.60 on zulip to talk about this |
I think that would be error prone. If you want to throw away items you can use |
I am not sure how error prone this will be, but as we start by adding this without implementing See #69985 (comment) where we previously discussed this. |
r? @sfackler |
☔ The latest upstream changes (presumably #76217) made this pull request unmergeable. Please resolve the merge conflicts. |
5236ad6
to
8bdf0f3
Compare
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
array::FillError
similar to array::FromIterator
array::FillError
similar to array::IntoIter
☔ The latest upstream changes (presumably #77172) made this pull request unmergeable. Please resolve the merge conflicts. Note that reviewers usually do not review pull requests until merge conflicts are resolved! Once you resolve the conflicts, you should change the labels applied by bors to indicate that your PR is ready for review. Post this as a comment to change the labels:
|
I think a const-generics-based crates.io has multiple |
I made a pre-rfc about having pure stack-based and hybrid stack/heap arrays on std -> https://github.com/c410-f3r/rfcs/blob/mem_structs/text/2946-mem_structs.md. If these structures are really desired, I can finish the RFC ASAP |
For what it’s worth I think the design of |
At least in my personal view adding something like I wrote and saw a few changes where smallvecs made performance worse due to slower lookup. So yeah, let's add something like |
@SimonSapin @lcnr Looks good! An I don't personally use |
Taken from #69985 without actually implementing
FromIterator
so we can merge this without having to worry aboutstabilizing 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 ofFromIterator
for arrays, once we implement this (requires at least stablemin_const_generics
). The current concept is to implementFromIterator
forResult<[T; N], FillError<T, N>>
, returning aFillError
if the iterator had less thanN
elements.Similar to
IntoIter
, we don't yet actually implementFromIterator
but instead add a probably permanently unstablenew
method toFillError
, meaning that one can now writeFillError::new().fill(iter).unwrap()
to collect into an array, which was previously not cleanly possible.