mhogrefe / malachite

An arbitrary-precision arithmetic library for Rust.
GNU Lesser General Public License v3.0
453 stars 18 forks source link

LimbIterator not correctly handle ExactSizeIterator::len() #18

Closed qingshi163 closed 1 year ago

qingshi163 commented 1 year ago

LimbIterator currently using the default implement of ExactSizeIterator witch calls Iterator::size_hint(). but it always return the full size of the limbs.

document for ExactSizeIterator::len():

Returns the exact remaining length of the iterator.

The implementation ensures that the iterator will return exactly len() more times a [Some(T)](https://doc.rust-lang.org/std/option/enum.Option.html#variant.Some) value, before returning [None](https://doc.rust-lang.org/std/option/enum.Option.html#variant.None). This method has a default implementation, so you usually should not implement it directly. However, if you can provide a more efficient implementation, you can do so. See the [trait-level](https://doc.rust-lang.org/std/iter/trait.ExactSizeIterator.html) docs for an example.

This function has the same safety guarantees as the [Iterator::size_hint](https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.size_hint) function.
mhogrefe commented 1 year ago

Thanks for bringing this to my attention. It will be fixed in the next release.

mhogrefe commented 1 year ago

Fixed in 0.4.0.