The iterators for iter() and strings() were less useful than iterators over the underlying slice of strings. This commit makes them more equivalent, without having to expose implementation details.
The underlying iterators are efficiently clonable (they're just a couple of pointers and, for Iter, a count) so this crate's iterators can be cloned efficiently too.
Similarly, slice and enumeration iterators can be efficiently navigated both forward and backward, and they're both fused iterators as well.
This does have forward-compatibility implications since this represents a promise that either future implementations will also be efficiently clonable and double-ended, or the semver will change.
A better way to get the same result would be to make iter() and strings() return impl Iterator<...> + Clone + DoubleEndedIterator + ExactSizeIterator + FusedIterator. That would also avoid a bunch of boilerplate and allow using the standard library's efficient implementations of methods like Iterator::nth, instead of the current use of the inefficient default implementations.
Unfortunately, support for impl Trait in associated types hasn't stabilized yet (rust-lang/rust#63063), so that would currently only work on nightly Rust.
The iterators for
iter()
andstrings()
were less useful than iterators over the underlying slice of strings. This commit makes them more equivalent, without having to expose implementation details.The underlying iterators are efficiently clonable (they're just a couple of pointers and, for
Iter
, a count) so this crate's iterators can be cloned efficiently too.Similarly, slice and enumeration iterators can be efficiently navigated both forward and backward, and they're both fused iterators as well.
This does have forward-compatibility implications since this represents a promise that either future implementations will also be efficiently clonable and double-ended, or the semver will change.
A better way to get the same result would be to make
iter()
andstrings()
returnimpl Iterator<...> + Clone + DoubleEndedIterator + ExactSizeIterator + FusedIterator
. That would also avoid a bunch of boilerplate and allow using the standard library's efficient implementations of methods likeIterator::nth
, instead of the current use of the inefficient default implementations.Unfortunately, support for
impl Trait
in associated types hasn't stabilized yet (rust-lang/rust#63063), so that would currently only work on nightly Rust.