3 /// An iterator that always continues to yield `None` when exhausted.
5 /// Calling next on a fused iterator that has returned `None` once is guaranteed
6 /// to return [`None`] again. This trait should be implemented by all iterators
7 /// that behave this way because it allows optimizing [`Iterator::fuse()`].
9 /// Note: In general, you should not use `FusedIterator` in generic bounds if
10 /// you need a fused iterator. Instead, you should just call [`Iterator::fuse()`]
11 /// on the iterator. If the iterator is already fused, the additional [`Fuse`]
12 /// wrapper will be a no-op with no performance penalty.
14 /// [`Fuse`]: crate::iter::Fuse
15 #[stable(feature = "fused", since = "1.26.0")]
16 #[rustc_unsafe_specialization_marker]
17 pub trait FusedIterator: Iterator {}
19 #[stable(feature = "fused", since = "1.26.0")]
20 impl<I: FusedIterator + ?Sized> FusedIterator for &mut I {}
22 /// An iterator that reports an accurate length using size_hint.
24 /// The iterator reports a size hint where it is either exact
25 /// (lower bound is equal to upper bound), or the upper bound is [`None`].
26 /// The upper bound must only be [`None`] if the actual iterator length is
27 /// larger than [`usize::MAX`]. In that case, the lower bound must be
28 /// [`usize::MAX`], resulting in an [`Iterator::size_hint()`] of
29 /// `(usize::MAX, None)`.
31 /// The iterator must produce exactly the number of elements it reported
32 /// or diverge before reaching the end.
36 /// This trait must only be implemented when the contract is upheld. Consumers
37 /// of this trait must inspect [`Iterator::size_hint()`]’s upper bound.
38 #[unstable(feature = "trusted_len", issue = "37572")]
39 #[rustc_unsafe_specialization_marker]
40 pub unsafe trait TrustedLen: Iterator {}
42 #[unstable(feature = "trusted_len", issue = "37572")]
43 unsafe impl<I: TrustedLen + ?Sized> TrustedLen for &mut I {}
45 /// An iterator that when yielding an item will have taken at least one element
46 /// from its underlying [`SourceIter`].
48 /// Calling any method that advances the iterator, e.g. [`next()`] or [`try_fold()`],
49 /// guarantees that for each step at least one value of the iterator's underlying source
50 /// has been moved out and the result of the iterator chain could be inserted
51 /// in its place, assuming structural constraints of the source allow such an insertion.
52 /// In other words this trait indicates that an iterator pipeline can be collected in place.
54 /// The primary use of this trait is in-place iteration. Refer to the [`vec::in_place_collect`]
55 /// module documentation for more information.
57 /// [`vec::in_place_collect`]: ../../../../alloc/vec/in_place_collect/index.html
58 /// [`SourceIter`]: crate::iter::SourceIter
59 /// [`next()`]: Iterator::next
60 /// [`try_fold()`]: Iterator::try_fold
61 #[unstable(issue = "none", feature = "inplace_iteration")]
63 pub unsafe trait InPlaceIterable: Iterator {}
65 /// A type that upholds all invariants of [`Step`].
67 /// The invariants of [`Step::steps_between()`] are a superset of the invariants
68 /// of [`TrustedLen`]. As such, [`TrustedLen`] is implemented for all range
69 /// types with the same generic type argument.
73 /// The implementation of [`Step`] for the given type must guarantee all
74 /// invariants of all methods are upheld. See the [`Step`] trait's documentation
75 /// for details. Consumers are free to rely on the invariants in unsafe code.
76 #[unstable(feature = "trusted_step", issue = "85731")]
77 #[rustc_specialization_trait]
78 pub unsafe trait TrustedStep: Step {}