- Feature Name: iterator_len_hint
- Start Date: 2015-04-05
- RFC PR: (leave this empty)
- Rust Issue: (leave this empty)
Deprecate Iterator::size_hint
for Iterator::len_hint
, and ExactSizeIterator
for ExactLengthIterator
, gaining consistency with the standard collections' naming convention.
Currently, methods returning the numbers of elements in containers are conventionally named len
in Rust, even for non-linear collections like BTreeMap
. But the Iterator
trait, which represents entities each yielding a sequence of elements, has a size_hint
method, instead of the more consistent len_hint
.
The standard library documentation says about size_hint
:
Returns a lower and upper bound on the remaining length of the iterator.
Additionally, there is an ExactSizeIterator
trait that also has an inconsistent name (but the sole method of ExactSizeIterator
is named len
, which is consistent).
So, some names should be changed. However, Rust 1.0 beta has already been released, which means deprecation should be favoured over direct renaming.
- Add
core::iter::Iterator::len_hint
, a method with an inlined default implementation simply callingself.size_hint()
. - Add
core::iter::ExactLengthIterator
, a re-export ofcore::iter::ExactSizeIterator
. - Deprecate
core::iter::Iterator::size_hint
andcore::iter::ExactSizeIterator
. - Adjust the
std
re-exports accordingly. - Deprecate the implementations of
size_hint
.
Later, in Rust 2.x series, remove size_hint
and ExactSizeIterator
.
This design is fully backwards compatible with Rust 1.0.0-beta.
Having deprecated items in the first stable release of Rust is a bit weird. However, this is only a minor drawback.
A. Directly rename size_hint
to len_hint
, and ExactSizeIterator
to ExactLengthIterator
during the 1.0 beta cycle.
This alternative is clearer than the main candidate.
However, this means late breaking changes, which are generally undesirable. If other breaking changes happen during the 1.0 beta cycle, then this alternative can "piggyback" on those changes.
Other than "not introducing deprecations now", the status quo doesn't have any advantage over the main candidate.
None.