about summary refs log tree commit diff
diff options
context:
space:
mode:
authorClar Fon <them@lightdark.xyz>2018-12-17 17:33:53 -0500
committerClar Fon <them@lightdark.xyz>2019-01-22 17:45:11 -0500
commit9228f3c6b2017993b0b829d60ecc51279e51ccb9 (patch)
treea1aa781cdf53fbdb87aaad940afc4d6687210d2c
parent4a036142a0da3cbae374f824a332bc43d4cecd09 (diff)
downloadrust-9228f3c6b2017993b0b829d60ecc51279e51ccb9.tar.gz
rust-9228f3c6b2017993b0b829d60ecc51279e51ccb9.zip
Move FusedIterator, TrustedLen to own module
-rw-r--r--src/libcore/iter/traits/marker.rs44
-rw-r--r--src/libcore/iter/traits/mod.rs47
2 files changed, 46 insertions, 45 deletions
diff --git a/src/libcore/iter/traits/marker.rs b/src/libcore/iter/traits/marker.rs
new file mode 100644
index 00000000000..602619bce5a
--- /dev/null
+++ b/src/libcore/iter/traits/marker.rs
@@ -0,0 +1,44 @@
+/// An iterator that always continues to yield `None` when exhausted.
+///
+/// Calling next on a fused iterator that has returned `None` once is guaranteed
+/// to return [`None`] again. This trait should be implemented by all iterators
+/// that behave this way because it allows optimizing [`Iterator::fuse`].
+///
+/// Note: In general, you should not use `FusedIterator` in generic bounds if
+/// you need a fused iterator. Instead, you should just call [`Iterator::fuse`]
+/// on the iterator. If the iterator is already fused, the additional [`Fuse`]
+/// wrapper will be a no-op with no performance penalty.
+///
+/// [`None`]: ../../std/option/enum.Option.html#variant.None
+/// [`Iterator::fuse`]: ../../std/iter/trait.Iterator.html#method.fuse
+/// [`Fuse`]: ../../std/iter/struct.Fuse.html
+#[stable(feature = "fused", since = "1.26.0")]
+pub trait FusedIterator: Iterator {}
+
+#[stable(feature = "fused", since = "1.26.0")]
+impl<I: FusedIterator + ?Sized> FusedIterator for &mut I {}
+
+/// An iterator that reports an accurate length using size_hint.
+///
+/// The iterator reports a size hint where it is either exact
+/// (lower bound is equal to upper bound), or the upper bound is [`None`].
+/// The upper bound must only be [`None`] if the actual iterator length is
+/// larger than [`usize::MAX`]. In that case, the lower bound must be
+/// [`usize::MAX`], resulting in a [`.size_hint`] of `(usize::MAX, None)`.
+///
+/// The iterator must produce exactly the number of elements it reported
+/// or diverge before reaching the end.
+///
+/// # Safety
+///
+/// This trait must only be implemented when the contract is upheld.
+/// Consumers of this trait must inspect [`.size_hint`]’s upper bound.
+///
+/// [`None`]: ../../std/option/enum.Option.html#variant.None
+/// [`usize::MAX`]: ../../std/usize/constant.MAX.html
+/// [`.size_hint`]: ../../std/iter/trait.Iterator.html#method.size_hint
+#[unstable(feature = "trusted_len", issue = "37572")]
+pub unsafe trait TrustedLen : Iterator {}
+
+#[unstable(feature = "trusted_len", issue = "37572")]
+unsafe impl<I: TrustedLen + ?Sized> TrustedLen for &mut I {}
diff --git a/src/libcore/iter/traits/mod.rs b/src/libcore/iter/traits/mod.rs
index 25637ef9f4e..000b9fad70b 100644
--- a/src/libcore/iter/traits/mod.rs
+++ b/src/libcore/iter/traits/mod.rs
@@ -3,54 +3,11 @@ mod double_ended;
 mod exact_size;
 mod collect;
 mod accum;
+mod marker;
 
 pub use self::iterator::Iterator;
 pub use self::double_ended::DoubleEndedIterator;
 pub use self::exact_size::ExactSizeIterator;
 pub use self::collect::{FromIterator, IntoIterator, Extend};
 pub use self::accum::{Sum, Product};
-
-/// An iterator that always continues to yield `None` when exhausted.
-///
-/// Calling next on a fused iterator that has returned `None` once is guaranteed
-/// to return [`None`] again. This trait should be implemented by all iterators
-/// that behave this way because it allows optimizing [`Iterator::fuse`].
-///
-/// Note: In general, you should not use `FusedIterator` in generic bounds if
-/// you need a fused iterator. Instead, you should just call [`Iterator::fuse`]
-/// on the iterator. If the iterator is already fused, the additional [`Fuse`]
-/// wrapper will be a no-op with no performance penalty.
-///
-/// [`None`]: ../../std/option/enum.Option.html#variant.None
-/// [`Iterator::fuse`]: ../../std/iter/trait.Iterator.html#method.fuse
-/// [`Fuse`]: ../../std/iter/struct.Fuse.html
-#[stable(feature = "fused", since = "1.26.0")]
-pub trait FusedIterator: Iterator {}
-
-#[stable(feature = "fused", since = "1.26.0")]
-impl<I: FusedIterator + ?Sized> FusedIterator for &mut I {}
-
-/// An iterator that reports an accurate length using size_hint.
-///
-/// The iterator reports a size hint where it is either exact
-/// (lower bound is equal to upper bound), or the upper bound is [`None`].
-/// The upper bound must only be [`None`] if the actual iterator length is
-/// larger than [`usize::MAX`]. In that case, the lower bound must be
-/// [`usize::MAX`], resulting in a [`.size_hint`] of `(usize::MAX, None)`.
-///
-/// The iterator must produce exactly the number of elements it reported
-/// or diverge before reaching the end.
-///
-/// # Safety
-///
-/// This trait must only be implemented when the contract is upheld.
-/// Consumers of this trait must inspect [`.size_hint`]’s upper bound.
-///
-/// [`None`]: ../../std/option/enum.Option.html#variant.None
-/// [`usize::MAX`]: ../../std/usize/constant.MAX.html
-/// [`.size_hint`]: ../../std/iter/trait.Iterator.html#method.size_hint
-#[unstable(feature = "trusted_len", issue = "37572")]
-pub unsafe trait TrustedLen : Iterator {}
-
-#[unstable(feature = "trusted_len", issue = "37572")]
-unsafe impl<I: TrustedLen + ?Sized> TrustedLen for &mut I {}
+pub use self::marker::{FusedIterator, TrustedLen};