]> git.lizzy.rs Git - rust.git/commit
Deprecate the rev_iter pattern in all places where a DoubleEndedIterator is provided...
authorJonathan S <gereeter@gmail.com>
Mon, 21 Apr 2014 04:59:12 +0000 (23:59 -0500)
committerJonathan S <gereeter@gmail.com>
Mon, 28 Apr 2014 21:45:36 +0000 (16:45 -0500)
commit03609e5a5e8bdca9452327d44e25407ce888d0bb
treeffef048a962111a82bdc86f7b060a8d2fa2c96f6
parentf58a8c9d760aead49e138fa8045e229a47217644
Deprecate the rev_iter pattern in all places where a DoubleEndedIterator is provided (everywhere but treemap)

This commit deprecates rev_iter, mut_rev_iter, move_rev_iter everywhere (except treemap) and also
deprecates related functions like rsplit, rev_components, and rev_str_components. In every case,
these functions can be replaced with the non-reversed form followed by a call to .rev(). To make this
more concrete, a translation table for all functional changes necessary follows:

* container.rev_iter() -> container.iter().rev()
* container.mut_rev_iter() -> container.mut_iter().rev()
* container.move_rev_iter() -> container.move_iter().rev()
* sliceorstr.rsplit(sep) -> sliceorstr.split(sep).rev()
* path.rev_components() -> path.components().rev()
* path.rev_str_components() -> path.str_components().rev()

In terms of the type system, this change also deprecates any specialized reversed iterator types (except
in treemap), opting instead to use Rev directly if any type annotations are needed. However, since
methods directly returning reversed iterators are now discouraged, the need for such annotations should
be small. However, in those cases, the general pattern for conversion is to take whatever follows Rev in
the original reversed name and surround it with Rev<>:

* RevComponents<'a> -> Rev<Components<'a>>
* RevStrComponents<'a> -> Rev<StrComponents<'a>>
* RevItems<'a, T> -> Rev<Items<'a, T>>
* etc.

The reasoning behind this change is that it makes the standard API much simpler without reducing readability,
performance, or power. The presence of functions such as rev_iter adds more boilerplate code to libraries
(all of which simply call .iter().rev()), clutters up the documentation, and only helps code by saving two
characters. Additionally, the numerous type synonyms that were used to make the type signatures look nice
like RevItems add even more boilerplate and clutter up the docs even more. With this change, all that cruft
goes away.

[breaking-change]
17 files changed:
src/doc/guide-container.md
src/libcollections/bitv.rs
src/libcollections/dlist.rs
src/libcollections/priority_queue.rs
src/libcollections/ringbuf.rs
src/libcollections/smallintmap.rs
src/libcollections/trie.rs
src/libnum/bigint.rs
src/librustc/middle/liveness.rs
src/librustc/middle/typeck/check/vtable.rs
src/librustdoc/lib.rs
src/libserialize/json.rs
src/libstd/path/posix.rs
src/libstd/path/windows.rs
src/libstd/slice.rs
src/libstd/str.rs
src/libsyntax/attr.rs