ibraheemdev / matchit

A high performance, zero-copy URL router.
https://docs.rs/matchit
MIT License
344 stars 35 forks source link

Implement `ExactSizeIterator` for `ParamsIter` or `Index` for `Params` #53

Closed Totodore closed 2 months ago

Totodore commented 3 months ago

Knowing the exact remaining length of the iterator would be nice in my use case, I'm deserializing params to T with serde and I need to keep track of the remaining length.

Because ParamsIter only wraps an std::slice::Iter, and that it already implements ExactSizeIterator we just have to forward the call to the inner Iter.

Another way to solve my issue would have been to directly use Params but I cannot access any elements because it doesn't implement Index.

What is your opinion on this @ibraheemdev? If you are ok with any of these two solution I will be happy to implement them.

ibraheemdev commented 2 months ago

Implementing ExactSizeIterator seems reasonable. I would prefer to avoid making Params indexable by usize to allow, for example, switching the underlying representation to be HashMap<&str, &str> without a breaking change.