Implement more Iterator methods on core::iter::Repeat · rust-lang/rust@963bd3b (original) (raw)

Original file line number Diff line number Diff line change
@@ -72,10 +72,32 @@ impl<A: Clone> Iterator for Repeat {
72 72 fn next(&mut self) -> Option<A> {
73 73 Some(self.element.clone())
74 74 }
75 +
75 76 #[inline]
76 77 fn size_hint(&self) -> (usize, Option<usize>) {
77 78 (usize::MAX, None)
78 79 }
80 +
81 +#[inline]
82 +fn advance_by(&mut self, n: usize) -> Result<(), usize> {
83 +// Advancing an infinite iterator of a single element is a no-op.
84 +let _ = n;
85 +Ok(())
86 +}
87 +
88 +#[inline]
89 +fn nth(&mut self, n: usize) -> Option<A> {
90 +let _ = n;
91 +Some(self.element.clone())
92 +}
93 +
94 +fn last(self) -> Option<A> {
95 +loop {}
96 +}
97 +
98 +fn count(self) -> usize {
99 +loop {}
100 +}
79 101 }
80 102
81 103 #[stable(feature = "rust1", since = "1.0.0")]
@@ -84,6 +106,19 @@ impl<A: Clone> DoubleEndedIterator for Repeat {
84 106 fn next_back(&mut self) -> Option<A> {
85 107 Some(self.element.clone())
86 108 }
109 +
110 +#[inline]
111 +fn advance_back_by(&mut self, n: usize) -> Result<(), usize> {
112 +// Advancing an infinite iterator of a single element is a no-op.
113 +let _ = n;
114 +Ok(())
115 +}
116 +
117 +#[inline]
118 +fn nth_back(&mut self, n: usize) -> Option<A> {
119 +let _ = n;
120 +Some(self.element.clone())
121 +}
87 122 }
88 123
89 124 #[stable(feature = "fused", since = "1.26.0")]