Skip to content

Commit 302de36

Browse files
committed
Properly link up iterator documentation
Due to the way iterators work, the std::iter module is chock full of structs that you, humble Rust programmer, will never actually use. However, they have URLs, and therefore get linked to, because they are real structs that do exist. So, rather than just have a tiny sentence about each one of them, this patch adds links back to the functions and methods on Iterator which actually create the structs, where helpful documentation already exists.
1 parent ec4362d commit 302de36

File tree

1 file changed

+137
-20
lines changed

1 file changed

+137
-20
lines changed

src/libcore/iter.rs

+137-20
Original file line numberDiff line numberDiff line change
@@ -1618,7 +1618,13 @@ impl<B, I: ExactSizeIterator, F> ExactSizeIterator for Map<I, F> where
16181618
impl<A, B> ExactSizeIterator for Zip<A, B>
16191619
where A: ExactSizeIterator, B: ExactSizeIterator {}
16201620

1621-
/// An double-ended iterator with the direction inverted
1621+
/// An double-ended iterator with the direction inverted.
1622+
///
1623+
/// This `struct` is created by the [`rev()`] method on [`Iterator`]. See its
1624+
/// documentation for more.
1625+
///
1626+
/// [`rev()`]: trait.Iterator.html#method.rev
1627+
/// [`Iterator`]: trait.Iterator.html
16221628
#[derive(Clone)]
16231629
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
16241630
#[stable(feature = "rust1", since = "1.0.0")]
@@ -1642,7 +1648,13 @@ impl<I> DoubleEndedIterator for Rev<I> where I: DoubleEndedIterator {
16421648
fn next_back(&mut self) -> Option<<I as Iterator>::Item> { self.iter.next() }
16431649
}
16441650

1645-
/// An iterator that clones the elements of an underlying iterator
1651+
/// An iterator that clones the elements of an underlying iterator.
1652+
///
1653+
/// This `struct` is created by the [`cloned()`] method on [`Iterator`]. See its
1654+
/// documentation for more.
1655+
///
1656+
/// [`cloned()`]: trait.Iterator.html#method.cloned
1657+
/// [`Iterator`]: trait.Iterator.html
16461658
#[stable(feature = "iter_cloned", since = "1.1.0")]
16471659
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
16481660
#[derive(Clone)]
@@ -1679,7 +1691,13 @@ impl<'a, I, T: 'a> ExactSizeIterator for Cloned<I>
16791691
where I: ExactSizeIterator<Item=&'a T>, T: Clone
16801692
{}
16811693

1682-
/// An iterator that repeats endlessly
1694+
/// An iterator that repeats endlessly.
1695+
///
1696+
/// This `struct` is created by the [`cycle()`] method on [`Iterator`]. See its
1697+
/// documentation for more.
1698+
///
1699+
/// [`cycle()`]: trait.Iterator.html#method.cycle
1700+
/// [`Iterator`]: trait.Iterator.html
16831701
#[derive(Clone)]
16841702
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
16851703
#[stable(feature = "rust1", since = "1.0.0")]
@@ -1711,7 +1729,13 @@ impl<I> Iterator for Cycle<I> where I: Clone + Iterator {
17111729
}
17121730
}
17131731

1714-
/// An iterator that strings two iterators together
1732+
/// An iterator that strings two iterators together.
1733+
///
1734+
/// This `struct` is created by the [`chain()`] method on [`Iterator`]. See its
1735+
/// documentation for more.
1736+
///
1737+
/// [`chain()`]: trait.Iterator.html#method.chain
1738+
/// [`Iterator`]: trait.Iterator.html
17151739
#[derive(Clone)]
17161740
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
17171741
#[stable(feature = "rust1", since = "1.0.0")]
@@ -1849,7 +1873,13 @@ impl<A, B> DoubleEndedIterator for Chain<A, B> where
18491873
}
18501874
}
18511875

1852-
/// An iterator that iterates two other iterators simultaneously
1876+
/// An iterator that iterates two other iterators simultaneously.
1877+
///
1878+
/// This `struct` is created by the [`zip()`] method on [`Iterator`]. See its
1879+
/// documentation for more.
1880+
///
1881+
/// [`zip()`]: trait.Iterator.html#method.zip
1882+
/// [`Iterator`]: trait.Iterator.html
18531883
#[derive(Clone)]
18541884
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
18551885
#[stable(feature = "rust1", since = "1.0.0")]
@@ -1915,7 +1945,13 @@ impl<A, B> DoubleEndedIterator for Zip<A, B> where
19151945
}
19161946
}
19171947

1918-
/// An iterator that maps the values of `iter` with `f`
1948+
/// An iterator that maps the values of `iter` with `f`.
1949+
///
1950+
/// This `struct` is created by the [`map()`] method on [`Iterator`]. See its
1951+
/// documentation for more.
1952+
///
1953+
/// [`map()`]: trait.Iterator.html#method.map
1954+
/// [`Iterator`]: trait.Iterator.html
19191955
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
19201956
#[stable(feature = "rust1", since = "1.0.0")]
19211957
#[derive(Clone)]
@@ -1949,7 +1985,13 @@ impl<B, I: DoubleEndedIterator, F> DoubleEndedIterator for Map<I, F> where
19491985
}
19501986
}
19511987

1952-
/// An iterator that filters the elements of `iter` with `predicate`
1988+
/// An iterator that filters the elements of `iter` with `predicate`.
1989+
///
1990+
/// This `struct` is created by the [`filter()`] method on [`Iterator`]. See its
1991+
/// documentation for more.
1992+
///
1993+
/// [`filter()`]: trait.Iterator.html#method.filter
1994+
/// [`Iterator`]: trait.Iterator.html
19531995
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
19541996
#[stable(feature = "rust1", since = "1.0.0")]
19551997
#[derive(Clone)]
@@ -1994,7 +2036,13 @@ impl<I: DoubleEndedIterator, P> DoubleEndedIterator for Filter<I, P>
19942036
}
19952037
}
19962038

1997-
/// An iterator that uses `f` to both filter and map elements from `iter`
2039+
/// An iterator that uses `f` to both filter and map elements from `iter`.
2040+
///
2041+
/// This `struct` is created by the [`filter_map()`] method on [`Iterator`]. See its
2042+
/// documentation for more.
2043+
///
2044+
/// [`filter_map()`]: trait.Iterator.html#method.filter_map
2045+
/// [`Iterator`]: trait.Iterator.html
19982046
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
19992047
#[stable(feature = "rust1", since = "1.0.0")]
20002048
#[derive(Clone)]
@@ -2041,7 +2089,13 @@ impl<B, I: DoubleEndedIterator, F> DoubleEndedIterator for FilterMap<I, F>
20412089
}
20422090
}
20432091

2044-
/// An iterator that yields the current count and the element during iteration
2092+
/// An iterator that yields the current count and the element during iteration.
2093+
///
2094+
/// This `struct` is created by the [`enumerate()`] method on [`Iterator`]. See its
2095+
/// documentation for more.
2096+
///
2097+
/// [`enumerate()`]: trait.Iterator.html#method.enumerate
2098+
/// [`Iterator`]: trait.Iterator.html
20452099
#[derive(Clone)]
20462100
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
20472101
#[stable(feature = "rust1", since = "1.0.0")]
@@ -2108,7 +2162,14 @@ impl<I> DoubleEndedIterator for Enumerate<I> where
21082162
}
21092163
}
21102164

2111-
/// An iterator with a `peek()` that returns an optional reference to the next element.
2165+
/// An iterator with a `peek()` that returns an optional reference to the next
2166+
/// element.
2167+
///
2168+
/// This `struct` is created by the [`peekable()`] method on [`Iterator`]. See its
2169+
/// documentation for more.
2170+
///
2171+
/// [`peekable()`]: trait.Iterator.html#method.peekable
2172+
/// [`Iterator`]: trait.Iterator.html
21122173
#[derive(Clone)]
21132174
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
21142175
#[stable(feature = "rust1", since = "1.0.0")]
@@ -2190,7 +2251,13 @@ impl<I: Iterator> Peekable<I> {
21902251
}
21912252
}
21922253

2193-
/// An iterator that rejects elements while `predicate` is true
2254+
/// An iterator that rejects elements while `predicate` is true.
2255+
///
2256+
/// This `struct` is created by the [`skip_while()`] method on [`Iterator`]. See its
2257+
/// documentation for more.
2258+
///
2259+
/// [`skip_while()`]: trait.Iterator.html#method.skip_while
2260+
/// [`Iterator`]: trait.Iterator.html
21942261
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
21952262
#[stable(feature = "rust1", since = "1.0.0")]
21962263
#[derive(Clone)]
@@ -2224,7 +2291,13 @@ impl<I: Iterator, P> Iterator for SkipWhile<I, P>
22242291
}
22252292
}
22262293

2227-
/// An iterator that only accepts elements while `predicate` is true
2294+
/// An iterator that only accepts elements while `predicate` is true.
2295+
///
2296+
/// This `struct` is created by the [`take_while()`] method on [`Iterator`]. See its
2297+
/// documentation for more.
2298+
///
2299+
/// [`take_while()`]: trait.Iterator.html#method.take_while
2300+
/// [`Iterator`]: trait.Iterator.html
22282301
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
22292302
#[stable(feature = "rust1", since = "1.0.0")]
22302303
#[derive(Clone)]
@@ -2264,6 +2337,12 @@ impl<I: Iterator, P> Iterator for TakeWhile<I, P>
22642337
}
22652338

22662339
/// An iterator that skips over `n` elements of `iter`.
2340+
///
2341+
/// This `struct` is created by the [`skip()`] method on [`Iterator`]. See its
2342+
/// documentation for more.
2343+
///
2344+
/// [`skip()`]: trait.Iterator.html#method.skip
2345+
/// [`Iterator`]: trait.Iterator.html
22672346
#[derive(Clone)]
22682347
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
22692348
#[stable(feature = "rust1", since = "1.0.0")]
@@ -2338,6 +2417,12 @@ impl<I> Iterator for Skip<I> where I: Iterator {
23382417
impl<I> ExactSizeIterator for Skip<I> where I: ExactSizeIterator {}
23392418

23402419
/// An iterator that only iterates over the first `n` iterations of `iter`.
2420+
///
2421+
/// This `struct` is created by the [`take()`] method on [`Iterator`]. See its
2422+
/// documentation for more.
2423+
///
2424+
/// [`take()`]: trait.Iterator.html#method.take
2425+
/// [`Iterator`]: trait.Iterator.html
23412426
#[derive(Clone)]
23422427
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
23432428
#[stable(feature = "rust1", since = "1.0.0")]
@@ -2393,7 +2478,13 @@ impl<I> Iterator for Take<I> where I: Iterator{
23932478
impl<I> ExactSizeIterator for Take<I> where I: ExactSizeIterator {}
23942479

23952480

2396-
/// An iterator to maintain state while iterating another iterator
2481+
/// An iterator to maintain state while iterating another iterator.
2482+
///
2483+
/// This `struct` is created by the [`scan()`] method on [`Iterator`]. See its
2484+
/// documentation for more.
2485+
///
2486+
/// [`scan()`]: trait.Iterator.html#method.scan
2487+
/// [`Iterator`]: trait.Iterator.html
23972488
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
23982489
#[stable(feature = "rust1", since = "1.0.0")]
23992490
#[derive(Clone)]
@@ -2422,9 +2513,14 @@ impl<B, I, St, F> Iterator for Scan<I, St, F> where
24222513
}
24232514
}
24242515

2425-
/// An iterator that maps each element to an iterator,
2426-
/// and yields the elements of the produced iterators
2516+
/// An iterator that maps each element to an iterator, and yields the elements
2517+
/// of the produced iterators.
24272518
///
2519+
/// This `struct` is created by the [`flat_map()`] method on [`Iterator`]. See its
2520+
/// documentation for more.
2521+
///
2522+
/// [`flat_map()`]: trait.Iterator.html#method.flat_map
2523+
/// [`Iterator`]: trait.Iterator.html
24282524
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
24292525
#[stable(feature = "rust1", since = "1.0.0")]
24302526
#[derive(Clone)]
@@ -2493,8 +2589,11 @@ impl<I: DoubleEndedIterator, U, F> DoubleEndedIterator for FlatMap<I, U, F> wher
24932589
/// An iterator that yields `None` forever after the underlying iterator
24942590
/// yields `None` once.
24952591
///
2496-
/// These can be created through
2497-
/// [`iter.fuse()`](trait.Iterator.html#method.fuse).
2592+
/// This `struct` is created by the [`fuse()`] method on [`Iterator`]. See its
2593+
/// documentation for more.
2594+
///
2595+
/// [`fuse()`]: trait.Iterator.html#method.fuse
2596+
/// [`Iterator`]: trait.Iterator.html
24982597
#[derive(Clone)]
24992598
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
25002599
#[stable(feature = "rust1", since = "1.0.0")]
@@ -2574,8 +2673,14 @@ impl<I> DoubleEndedIterator for Fuse<I> where I: DoubleEndedIterator {
25742673
#[stable(feature = "rust1", since = "1.0.0")]
25752674
impl<I> ExactSizeIterator for Fuse<I> where I: ExactSizeIterator {}
25762675

2577-
/// An iterator that calls a function with a reference to each
2578-
/// element before yielding it.
2676+
/// An iterator that calls a function with a reference to each element before
2677+
/// yielding it.
2678+
///
2679+
/// This `struct` is created by the [`inspect()`] method on [`Iterator`]. See its
2680+
/// documentation for more.
2681+
///
2682+
/// [`inspect()`]: trait.Iterator.html#method.inspect
2683+
/// [`Iterator`]: trait.Iterator.html
25792684
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
25802685
#[stable(feature = "rust1", since = "1.0.0")]
25812686
#[derive(Clone)]
@@ -3009,7 +3114,11 @@ impl<A: Step + One> Iterator for ops::RangeFrom<A> where
30093114
}
30103115
}
30113116

3012-
/// An iterator that repeats an element endlessly
3117+
/// An iterator that repeats an element endlessly.
3118+
///
3119+
/// This `struct` is created by the [`repeat()`] function. See its documentation for more.
3120+
///
3121+
/// [`repeat()`]: fn.repeat.html
30133122
#[derive(Clone)]
30143123
#[stable(feature = "rust1", since = "1.0.0")]
30153124
pub struct Repeat<A> {
@@ -3040,6 +3149,10 @@ pub fn repeat<T: Clone>(elt: T) -> Repeat<T> {
30403149
}
30413150

30423151
/// An iterator that yields nothing.
3152+
///
3153+
/// This `struct` is created by the [`empty()`] function. See its documentation for more.
3154+
///
3155+
/// [`empty()`]: fn.empty.html
30433156
#[stable(feature = "iter_empty", since = "1.2.0")]
30443157
pub struct Empty<T>(marker::PhantomData<T>);
30453158

@@ -3095,6 +3208,10 @@ pub fn empty<T>() -> Empty<T> {
30953208
}
30963209

30973210
/// An iterator that yields an element exactly once.
3211+
///
3212+
/// This `struct` is created by the [`once()`] function. See its documentation for more.
3213+
///
3214+
/// [`once()`]: fn.once.html
30983215
#[derive(Clone)]
30993216
#[stable(feature = "iter_once", since = "1.2.0")]
31003217
pub struct Once<T> {

0 commit comments

Comments
 (0)