diff --git a/library/core/src/iter/adapters/cloned.rs b/library/core/src/iter/adapters/cloned.rs index aba24a79dcf79..b98d6b6fd843a 100644 --- a/library/core/src/iter/adapters/cloned.rs +++ b/library/core/src/iter/adapters/cloned.rs @@ -22,6 +22,18 @@ impl Cloned { pub(in crate::iter) fn new(it: I) -> Cloned { Cloned { it } } + + /// Returns a reference to the inner iterator. + #[unstable(feature = "inner_adaptor", issue = "103302", reason = "recently added")] + pub fn inner(&self) -> &I { + &self.it + } + + /// Consumes the adaptor struct and returns the inner iterator. + #[unstable(feature = "inner_adaptor", issue = "103302", reason = "recently added")] + pub fn into_inner(self) -> I { + self.it + } } fn clone_try_fold(mut f: impl FnMut(Acc, T) -> R) -> impl FnMut(Acc, &T) -> R { diff --git a/library/core/src/iter/adapters/copied.rs b/library/core/src/iter/adapters/copied.rs index 62d3afb81603d..ae3f1999ce6d6 100644 --- a/library/core/src/iter/adapters/copied.rs +++ b/library/core/src/iter/adapters/copied.rs @@ -25,6 +25,18 @@ impl Copied { pub(in crate::iter) fn new(it: I) -> Copied { Copied { it } } + + /// Returns a reference to the inner iterator. + #[unstable(feature = "inner_adaptor", issue = "103302", reason = "recently added")] + pub fn inner(&self) -> &I { + &self.it + } + + /// Consumes the adaptor struct and returns the inner iterator. + #[unstable(feature = "inner_adaptor", issue = "103302", reason = "recently added")] + pub fn into_inner(self) -> I { + self.it + } } fn copy_fold(mut f: impl FnMut(Acc, T) -> Acc) -> impl FnMut(Acc, &T) -> Acc { diff --git a/library/core/src/iter/adapters/enumerate.rs b/library/core/src/iter/adapters/enumerate.rs index 14a126951115c..d031a4149d90d 100644 --- a/library/core/src/iter/adapters/enumerate.rs +++ b/library/core/src/iter/adapters/enumerate.rs @@ -22,6 +22,18 @@ impl Enumerate { pub(in crate::iter) fn new(iter: I) -> Enumerate { Enumerate { iter, count: 0 } } + + /// Returns a reference to the inner iterator. + #[unstable(feature = "inner_adaptor", issue = "103302", reason = "recently added")] + pub fn inner(&self) -> &I { + &self.iter + } + + /// Consumes the adaptor struct and returns the inner iterator. + #[unstable(feature = "inner_adaptor", issue = "103302", reason = "recently added")] + pub fn into_inner(self) -> I { + self.iter + } } #[stable(feature = "rust1", since = "1.0.0")] diff --git a/library/core/src/iter/adapters/filter.rs b/library/core/src/iter/adapters/filter.rs index a0afaa326ad63..d04bf40572d8c 100644 --- a/library/core/src/iter/adapters/filter.rs +++ b/library/core/src/iter/adapters/filter.rs @@ -21,6 +21,18 @@ impl Filter { pub(in crate::iter) fn new(iter: I, predicate: P) -> Filter { Filter { iter, predicate } } + + /// Returns a reference to the inner iterator. + #[unstable(feature = "inner_adaptor", issue = "103302", reason = "recently added")] + pub fn inner(&self) -> &I { + &self.iter + } + + /// Consumes the adaptor struct and returns the inner iterator. + #[unstable(feature = "inner_adaptor", issue = "103302", reason = "recently added")] + pub fn into_inner(self) -> I { + self.iter + } } #[stable(feature = "core_impl_debug", since = "1.9.0")] diff --git a/library/core/src/iter/adapters/filter_map.rs b/library/core/src/iter/adapters/filter_map.rs index e0d665c9e12ba..e29f91f6a3269 100644 --- a/library/core/src/iter/adapters/filter_map.rs +++ b/library/core/src/iter/adapters/filter_map.rs @@ -20,6 +20,18 @@ impl FilterMap { pub(in crate::iter) fn new(iter: I, f: F) -> FilterMap { FilterMap { iter, f } } + + /// Returns a reference to the inner iterator. + #[unstable(feature = "inner_adaptor", issue = "103302", reason = "recently added")] + pub fn inner(&self) -> &I { + &self.iter + } + + /// Consumes the adaptor struct and returns the inner iterator. + #[unstable(feature = "inner_adaptor", issue = "103302", reason = "recently added")] + pub fn into_inner(self) -> I { + self.iter + } } #[stable(feature = "core_impl_debug", since = "1.9.0")] diff --git a/library/core/src/iter/adapters/inspect.rs b/library/core/src/iter/adapters/inspect.rs index 19839fdfe5bc3..9a3248f689d44 100644 --- a/library/core/src/iter/adapters/inspect.rs +++ b/library/core/src/iter/adapters/inspect.rs @@ -21,6 +21,18 @@ impl Inspect { pub(in crate::iter) fn new(iter: I, f: F) -> Inspect { Inspect { iter, f } } + + /// Returns a reference to the inner iterator. + #[unstable(feature = "inner_adaptor", issue = "103302", reason = "recently added")] + pub fn inner(&self) -> &I { + &self.iter + } + + /// Consumes the adaptor struct and returns the inner iterator. + #[unstable(feature = "inner_adaptor", issue = "103302", reason = "recently added")] + pub fn into_inner(self) -> I { + self.iter + } } #[stable(feature = "core_impl_debug", since = "1.9.0")] diff --git a/library/core/src/iter/adapters/intersperse.rs b/library/core/src/iter/adapters/intersperse.rs index d8bbd424cf258..58b9ce125bf36 100644 --- a/library/core/src/iter/adapters/intersperse.rs +++ b/library/core/src/iter/adapters/intersperse.rs @@ -22,6 +22,18 @@ where pub(in crate::iter) fn new(iter: I, separator: I::Item) -> Self { Self { iter: iter.peekable(), separator, needs_sep: false } } + + /// Returns a reference to the inner iterator. + #[unstable(feature = "inner_adaptor", issue = "103302", reason = "recently added")] + pub fn inner(&self) -> &I { + &self.iter.inner() + } + + /// Consumes the adaptor struct and returns the inner iterator. + #[unstable(feature = "inner_adaptor", issue = "103302", reason = "recently added")] + pub fn into_inner(self) -> I { + self.iter.into_inner() + } } #[unstable(feature = "iter_intersperse", reason = "recently added", issue = "79524")] diff --git a/library/core/src/iter/adapters/map.rs b/library/core/src/iter/adapters/map.rs index 9e25dbe462c91..28d8b404d5eec 100644 --- a/library/core/src/iter/adapters/map.rs +++ b/library/core/src/iter/adapters/map.rs @@ -68,6 +68,18 @@ impl Map { pub(in crate::iter) fn new(iter: I, f: F) -> Map { Map { iter, f } } + + /// Returns a reference to the inner iterator. + #[unstable(feature = "inner_adaptor", issue = "103302", reason = "recently added")] + pub fn inner(&self) -> &I { + &self.iter + } + + /// Consumes the adaptor struct and returns the inner iterator. + #[unstable(feature = "inner_adaptor", issue = "103302", reason = "recently added")] + pub fn into_inner(self) -> I { + self.iter + } } #[stable(feature = "core_impl_debug", since = "1.9.0")] diff --git a/library/core/src/iter/adapters/map_while.rs b/library/core/src/iter/adapters/map_while.rs index fbdeca4d4ee4f..35ae707c6aa7f 100644 --- a/library/core/src/iter/adapters/map_while.rs +++ b/library/core/src/iter/adapters/map_while.rs @@ -21,6 +21,18 @@ impl MapWhile { pub(in crate::iter) fn new(iter: I, predicate: P) -> MapWhile { MapWhile { iter, predicate } } + + /// Returns a reference to the inner iterator. + #[unstable(feature = "inner_adaptor", issue = "103302", reason = "recently added")] + pub fn inner(&self) -> &I { + &self.iter + } + + /// Consumes the adaptor struct and returns the inner iterator. + #[unstable(feature = "inner_adaptor", issue = "103302", reason = "recently added")] + pub fn into_inner(self) -> I { + self.iter + } } #[stable(feature = "iter_map_while", since = "1.57.0")] diff --git a/library/core/src/iter/adapters/peekable.rs b/library/core/src/iter/adapters/peekable.rs index 20aca323bab79..2ed3b0afecc12 100644 --- a/library/core/src/iter/adapters/peekable.rs +++ b/library/core/src/iter/adapters/peekable.rs @@ -22,6 +22,18 @@ impl Peekable { pub(in crate::iter) fn new(iter: I) -> Peekable { Peekable { iter, peeked: None } } + + /// Returns a reference to the inner iterator. + #[unstable(feature = "inner_adaptor", issue = "103302", reason = "recently added")] + pub fn inner(&self) -> &I { + &self.iter + } + + /// Consumes the peekable and returns the inner iterator. + #[unstable(feature = "inner_adaptor", issue = "103302", reason = "recently added")] + pub fn into_inner(self) -> I { + self.iter + } } // Peekable must remember if a None has been seen in the `.peek()` method. diff --git a/library/core/src/iter/adapters/rev.rs b/library/core/src/iter/adapters/rev.rs index 139fb7bbdd996..dfe3acbf53e75 100644 --- a/library/core/src/iter/adapters/rev.rs +++ b/library/core/src/iter/adapters/rev.rs @@ -19,6 +19,18 @@ impl Rev { pub(in crate::iter) fn new(iter: T) -> Rev { Rev { iter } } + + /// Returns a reference to the inner iterator. + #[unstable(feature = "inner_adaptor", issue = "103302", reason = "recently added")] + pub fn inner(&self) -> &T { + &self.iter + } + + /// Consumes the adaptor struct and returns the inner iterator. + #[unstable(feature = "inner_adaptor", issue = "103302", reason = "recently added")] + pub fn into_inner(self) -> T { + self.iter + } } #[stable(feature = "rust1", since = "1.0.0")] diff --git a/library/core/src/iter/adapters/scan.rs b/library/core/src/iter/adapters/scan.rs index 62470512cc747..60b8f4a66d04c 100644 --- a/library/core/src/iter/adapters/scan.rs +++ b/library/core/src/iter/adapters/scan.rs @@ -22,6 +22,18 @@ impl Scan { pub(in crate::iter) fn new(iter: I, state: St, f: F) -> Scan { Scan { iter, state, f } } + + /// Returns a reference to the inner iterator. + #[unstable(feature = "inner_adaptor", issue = "103302", reason = "recently added")] + pub fn inner(&self) -> &I { + &self.iter + } + + /// Consumes the adaptor struct and returns the inner iterator. + #[unstable(feature = "inner_adaptor", issue = "103302", reason = "recently added")] + pub fn into_inner(self) -> I { + self.iter + } } #[stable(feature = "core_impl_debug", since = "1.9.0")] diff --git a/library/core/src/iter/adapters/skip.rs b/library/core/src/iter/adapters/skip.rs index c6334880db57c..e80e7836235ad 100644 --- a/library/core/src/iter/adapters/skip.rs +++ b/library/core/src/iter/adapters/skip.rs @@ -21,6 +21,18 @@ impl Skip { pub(in crate::iter) fn new(iter: I, n: usize) -> Skip { Skip { iter, n } } + + /// Returns a reference to the inner iterator. + #[unstable(feature = "inner_adaptor", issue = "103302", reason = "recently added")] + pub fn inner(&self) -> &I { + &self.iter + } + + /// Consumes the adaptor struct and returns the inner iterator. + #[unstable(feature = "inner_adaptor", issue = "103302", reason = "recently added")] + pub fn into_inner(self) -> I { + self.iter + } } #[stable(feature = "rust1", since = "1.0.0")] diff --git a/library/core/src/iter/adapters/skip_while.rs b/library/core/src/iter/adapters/skip_while.rs index f29661779c056..42a53ef9db289 100644 --- a/library/core/src/iter/adapters/skip_while.rs +++ b/library/core/src/iter/adapters/skip_while.rs @@ -22,6 +22,18 @@ impl SkipWhile { pub(in crate::iter) fn new(iter: I, predicate: P) -> SkipWhile { SkipWhile { iter, flag: false, predicate } } + + /// Returns a reference to the inner iterator. + #[unstable(feature = "inner_adaptor", issue = "103302", reason = "recently added")] + pub fn inner(&self) -> &I { + &self.iter + } + + /// Consumes the adaptor struct and returns the inner iterator. + #[unstable(feature = "inner_adaptor", issue = "103302", reason = "recently added")] + pub fn into_inner(self) -> I { + self.iter + } } #[stable(feature = "core_impl_debug", since = "1.9.0")] diff --git a/library/core/src/iter/adapters/step_by.rs b/library/core/src/iter/adapters/step_by.rs index 4252c34a0e0fc..b2c7fcf8dcc4e 100644 --- a/library/core/src/iter/adapters/step_by.rs +++ b/library/core/src/iter/adapters/step_by.rs @@ -21,6 +21,18 @@ impl StepBy { assert!(step != 0); StepBy { iter, step: step - 1, first_take: true } } + + /// Returns a reference to the inner iterator. + #[unstable(feature = "inner_adaptor", issue = "103302", reason = "recently added")] + pub fn inner(&self) -> &I { + &self.iter + } + + /// Consumes the adaptor struct and returns the inner iterator. + #[unstable(feature = "inner_adaptor", issue = "103302", reason = "recently added")] + pub fn into_inner(self) -> I { + self.iter + } } #[stable(feature = "iterator_step_by", since = "1.28.0")] diff --git a/library/core/src/iter/adapters/take.rs b/library/core/src/iter/adapters/take.rs index 58a0b9d7bbe99..7f0a479130d7e 100644 --- a/library/core/src/iter/adapters/take.rs +++ b/library/core/src/iter/adapters/take.rs @@ -21,6 +21,18 @@ impl Take { pub(in crate::iter) fn new(iter: I, n: usize) -> Take { Take { iter, n } } + + /// Returns a reference to the inner iterator. + #[unstable(feature = "inner_adaptor", issue = "103302", reason = "recently added")] + pub fn inner(&self) -> &I { + &self.iter + } + + /// Consumes the adaptor struct and returns the inner iterator. + #[unstable(feature = "inner_adaptor", issue = "103302", reason = "recently added")] + pub fn into_inner(self) -> I { + self.iter + } } #[stable(feature = "rust1", since = "1.0.0")] diff --git a/library/core/src/iter/adapters/take_while.rs b/library/core/src/iter/adapters/take_while.rs index ec66dc3aec360..0dc03e2aeb8fb 100644 --- a/library/core/src/iter/adapters/take_while.rs +++ b/library/core/src/iter/adapters/take_while.rs @@ -22,6 +22,18 @@ impl TakeWhile { pub(in crate::iter) fn new(iter: I, predicate: P) -> TakeWhile { TakeWhile { iter, flag: false, predicate } } + + /// Returns a reference to the inner iterator. + #[unstable(feature = "inner_adaptor", issue = "103302", reason = "recently added")] + pub fn inner(&self) -> &I { + &self.iter + } + + /// Consumes the adaptor struct and returns the inner iterator. + #[unstable(feature = "inner_adaptor", issue = "103302", reason = "recently added")] + pub fn into_inner(self) -> I { + self.iter + } } #[stable(feature = "core_impl_debug", since = "1.9.0")] diff --git a/library/core/src/iter/adapters/zip.rs b/library/core/src/iter/adapters/zip.rs index 8153c8cfef133..f8177c609ea45 100644 --- a/library/core/src/iter/adapters/zip.rs +++ b/library/core/src/iter/adapters/zip.rs @@ -31,6 +31,24 @@ impl Zip { } None } + + /// Returns a reference to the left inner iterator. + #[unstable(feature = "inner_adaptor", issue = "103302", reason = "recently added")] + pub fn left_inner(&self) -> &A { + &self.a + } + + /// Returns a reference to the right inner iterator. + #[unstable(feature = "inner_adaptor", issue = "103302", reason = "recently added")] + pub fn right_inner(&self) -> &B { + &self.b + } + + /// Consumes the adaptor struct and returns the inner iterator. + #[unstable(feature = "inner_adaptor", issue = "103302", reason = "recently added")] + pub fn into_inner(self) -> (A, B) { + (self.a, self.b) + } } /// Converts the arguments to iterators and zips them.