shnewto / bnf

Parse BNF grammar definitions
MIT License
256 stars 22 forks source link

Iterator::size_hint #94

Closed CrockAgile closed 2 years ago

CrockAgile commented 2 years ago

Iterator::size_hint helps consumers by providing some hint of the iterator's size. This benefits patterns like collecting an iterator into a vec (iter.collect::<Vec<_>>()) because the collection can reserve the correct space, without requiring re-allocations.

BNF's iterators currently hold slices internally, so the size_hint should be quite simple to implement (iterator impl search link)

There are 3 (or 4 once #92 is merged) Iterators to update: