]> git.lizzy.rs Git - rust.git/blob - src/libcore/iter/traits/marker.rs
Intra doc for iter marker traits
[rust.git] / src / libcore / iter / traits / marker.rs
1 /// An iterator that always continues to yield `None` when exhausted.
2 ///
3 /// Calling next on a fused iterator that has returned `None` once is guaranteed
4 /// to return [`None`] again. This trait should be implemented by all iterators
5 /// that behave this way because it allows optimizing [`Iterator::fuse`].
6 ///
7 /// Note: In general, you should not use `FusedIterator` in generic bounds if
8 /// you need a fused iterator. Instead, you should just call [`Iterator::fuse`]
9 /// on the iterator. If the iterator is already fused, the additional [`Fuse`]
10 /// wrapper will be a no-op with no performance penalty.
11 ///
12 /// [`Iterator::fuse`]: crate::iter::Iterator::fuse
13 /// [`Fuse`]: crate::iter::Fuse
14 #[stable(feature = "fused", since = "1.26.0")]
15 #[rustc_unsafe_specialization_marker]
16 pub trait FusedIterator: Iterator {}
17
18 #[stable(feature = "fused", since = "1.26.0")]
19 impl<I: FusedIterator + ?Sized> FusedIterator for &mut I {}
20
21 /// An iterator that reports an accurate length using size_hint.
22 ///
23 /// The iterator reports a size hint where it is either exact
24 /// (lower bound is equal to upper bound), or the upper bound is [`None`].
25 /// The upper bound must only be [`None`] if the actual iterator length is
26 /// larger than [`usize::MAX`]. In that case, the lower bound must be
27 /// [`usize::MAX`], resulting in a [`.size_hint`] of `(usize::MAX, None)`.
28 ///
29 /// The iterator must produce exactly the number of elements it reported
30 /// or diverge before reaching the end.
31 ///
32 /// # Safety
33 ///
34 /// This trait must only be implemented when the contract is upheld.
35 /// Consumers of this trait must inspect [`.size_hint`]’s upper bound.
36 ///
37 /// [`usize::MAX`]: crate::usize::MAX
38 /// [`.size_hint`]: crate::iter::Iterator::size_hint
39 #[unstable(feature = "trusted_len", issue = "37572")]
40 #[rustc_unsafe_specialization_marker]
41 pub unsafe trait TrustedLen: Iterator {}
42
43 #[unstable(feature = "trusted_len", issue = "37572")]
44 unsafe impl<I: TrustedLen + ?Sized> TrustedLen for &mut I {}