You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
chunks_exact variant with const generic argument #60735
to_array() could be a new function related to take(), it collects the first N items of an iterator into an array of length given as const generic argument (it panics if the iterator isn't long enough).
Usable like this (using iterate() from itertools):
let nine_foos = iterate(first, |p| foo(p)).to_array::<_, 9>();
to_array() could be a new function related to take(), it collects the first N items of an iterator into an array of length given as const generic argument (it panics if the iterator isn't long enough).
Usable like this (using iterate() from itertools):
let nine_foos = iterate(first, |p| foo(p)).to_array::<_, 9>();
I'd rather implement FromIterator for any [T; N], as that gives you the ability to write iterator.collect::<[_, 10]>(). .to_array could then just forward to that :)
Activity
varkor commentedon May 11, 2019
This also applies to the
windowsmethod on slices.varkor commentedon May 31, 2019
We should actually be able to implement this and test it out unstably now.
DutchGhost commentedon Mar 27, 2020
Im willing to give this a shot in the weekend and next week!
Dylan-DPC-zz commentedon Mar 27, 2020
@rustbot assign @DutchGhost
DutchGhost commentedon Mar 28, 2020
So, a simple PoC fails to compile horribly
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=770bf3df27b12c5ce77d5b2a91c5b110
Backtrace
DutchGhost commentedon Mar 28, 2020
Notice that a freestanding function does work:
DutchGhost commentedon Mar 30, 2020
The more I go into this, the more obstacles I stumble upon.
Below a list of all ICE's I encountered:
#70586
#70507
#68596
leonardo-m commentedon Mar 30, 2020
Keep going on, those bugs/limitations are worth fixing anyway :)
leonardo-m commentedon Apr 3, 2020
to_array() could be a new function related to take(), it collects the first N items of an iterator into an array of length given as const generic argument (it panics if the iterator isn't long enough).
Usable like this (using iterate() from itertools):
DutchGhost commentedon Apr 3, 2020
I'd rather implementFromIteratorfor any[T; N], as that gives you the ability to writeiterator.collect::<[_, 10]>()..to_arraycould then just forward to that :)EDIT: This is already PR'd: #69985
leonardo-m commentedon Apr 4, 2020
We need a good built-in static_assert that works with constant generics too :)
Auto merge of rust-lang#74373 - lcnr:array_chunks, r=withoutboats