From f165ff418d8679d7b5cc378dbde88874dc6d5459 Mon Sep 17 00:00:00 2001 From: Rayyan K <163682431+x4exr@users.noreply.github.com> Date: Sat, 21 Sep 2024 23:02:39 -0400 Subject: [PATCH 1/7] Add `peek_index` to `Enumerate` --- library/core/src/iter/adapters/enumerate.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/library/core/src/iter/adapters/enumerate.rs b/library/core/src/iter/adapters/enumerate.rs index ac15e3767fc09..1cd3c6f4f43ee 100644 --- a/library/core/src/iter/adapters/enumerate.rs +++ b/library/core/src/iter/adapters/enumerate.rs @@ -23,6 +23,10 @@ impl Enumerate { pub(in crate::iter) fn new(iter: I) -> Enumerate { Enumerate { iter, count: 0 } } + + pub fn peek_index(&self) -> usize { + self.count + } } #[stable(feature = "rust1", since = "1.0.0")] From 6e10d65e9597149d8a2300d9d3316bb2085af4a1 Mon Sep 17 00:00:00 2001 From: Rayyan K <163682431+x4exr@users.noreply.github.com> Date: Sun, 22 Sep 2024 17:36:45 +0000 Subject: [PATCH 2/7] Add unstable attribute with tracking issue to `peek_index` --- library/core/src/iter/adapters/enumerate.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/library/core/src/iter/adapters/enumerate.rs b/library/core/src/iter/adapters/enumerate.rs index 1cd3c6f4f43ee..24c3f9cf13f24 100644 --- a/library/core/src/iter/adapters/enumerate.rs +++ b/library/core/src/iter/adapters/enumerate.rs @@ -24,6 +24,8 @@ impl Enumerate { Enumerate { iter, count: 0 } } + #[inline] + #[unstable(feature = "peek_index", issue = "130711")] pub fn peek_index(&self) -> usize { self.count } From fb199e0e7e2a92b5afe34e19ab5b9dedce1c84c3 Mon Sep 17 00:00:00 2001 From: Rayyan K <163682431+x4exr@users.noreply.github.com> Date: Sun, 22 Sep 2024 18:14:43 +0000 Subject: [PATCH 3/7] Add missing documentation on public method. --- library/core/src/iter/adapters/enumerate.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/library/core/src/iter/adapters/enumerate.rs b/library/core/src/iter/adapters/enumerate.rs index 24c3f9cf13f24..4fa71663844dd 100644 --- a/library/core/src/iter/adapters/enumerate.rs +++ b/library/core/src/iter/adapters/enumerate.rs @@ -24,6 +24,9 @@ impl Enumerate { Enumerate { iter, count: 0 } } + /// Retrieve the current position of the iterator. + /// + /// If the iterator has not advanced, the position returned will be 0. #[inline] #[unstable(feature = "peek_index", issue = "130711")] pub fn peek_index(&self) -> usize { From cfe6e65c979b89ef0d644fbbdfc97c877f45d9c4 Mon Sep 17 00:00:00 2001 From: Rayyan K <163682431+x4exr@users.noreply.github.com> Date: Sun, 22 Sep 2024 18:18:14 +0000 Subject: [PATCH 4/7] Included more documentation regarding the expected use case --- library/core/src/iter/adapters/enumerate.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/library/core/src/iter/adapters/enumerate.rs b/library/core/src/iter/adapters/enumerate.rs index 4fa71663844dd..5a1195cdaa647 100644 --- a/library/core/src/iter/adapters/enumerate.rs +++ b/library/core/src/iter/adapters/enumerate.rs @@ -26,7 +26,10 @@ impl Enumerate { /// Retrieve the current position of the iterator. /// - /// If the iterator has not advanced, the position returned will be 0. + /// If the iterator has not advanced, the position returned will be 0. + /// + /// The position may also exceed the bounds of the iterator to allow for calculating + /// the displacment of the iterator from following calls to next. #[inline] #[unstable(feature = "peek_index", issue = "130711")] pub fn peek_index(&self) -> usize { From 1c492253925997f3b96f7a60c383559117be9bb9 Mon Sep 17 00:00:00 2001 From: Rayyan K <163682431+x4exr@users.noreply.github.com> Date: Sun, 22 Sep 2024 18:22:24 +0000 Subject: [PATCH 5/7] Replaced reference to next in doc with [`Iterator::next`] --- library/core/src/iter/adapters/enumerate.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/iter/adapters/enumerate.rs b/library/core/src/iter/adapters/enumerate.rs index 5a1195cdaa647..184fce013bfb5 100644 --- a/library/core/src/iter/adapters/enumerate.rs +++ b/library/core/src/iter/adapters/enumerate.rs @@ -29,7 +29,7 @@ impl Enumerate { /// If the iterator has not advanced, the position returned will be 0. /// /// The position may also exceed the bounds of the iterator to allow for calculating - /// the displacment of the iterator from following calls to next. + /// the displacment of the iterator from following calls to [`Iterator::next`]. #[inline] #[unstable(feature = "peek_index", issue = "130711")] pub fn peek_index(&self) -> usize { From 66343c695843f4ba694bc7785d34fb364a4a4376 Mon Sep 17 00:00:00 2001 From: Rayyan K <163682431+x4exr@users.noreply.github.com> Date: Sun, 22 Sep 2024 18:38:19 +0000 Subject: [PATCH 6/7] Ran `./x.py fmt` --- library/core/src/iter/adapters/enumerate.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/core/src/iter/adapters/enumerate.rs b/library/core/src/iter/adapters/enumerate.rs index 184fce013bfb5..e8c2737e78482 100644 --- a/library/core/src/iter/adapters/enumerate.rs +++ b/library/core/src/iter/adapters/enumerate.rs @@ -26,10 +26,10 @@ impl Enumerate { /// Retrieve the current position of the iterator. /// - /// If the iterator has not advanced, the position returned will be 0. + /// If the iterator has not advanced, the position returned will be 0. /// - /// The position may also exceed the bounds of the iterator to allow for calculating - /// the displacment of the iterator from following calls to [`Iterator::next`]. + /// The position may also exceed the bounds of the iterator to allow for calculating + /// the displacment of the iterator from following calls to [`Iterator::next`]. #[inline] #[unstable(feature = "peek_index", issue = "130711")] pub fn peek_index(&self) -> usize { From d8f391f38fbf3370ab72243207c7f9f38848cd5d Mon Sep 17 00:00:00 2001 From: Rayyan K <163682431+x4exr@users.noreply.github.com> Date: Sun, 22 Sep 2024 18:41:26 +0000 Subject: [PATCH 7/7] Fix typo in doc comment --- library/core/src/iter/adapters/enumerate.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/iter/adapters/enumerate.rs b/library/core/src/iter/adapters/enumerate.rs index e8c2737e78482..c9336035f8e04 100644 --- a/library/core/src/iter/adapters/enumerate.rs +++ b/library/core/src/iter/adapters/enumerate.rs @@ -29,7 +29,7 @@ impl Enumerate { /// If the iterator has not advanced, the position returned will be 0. /// /// The position may also exceed the bounds of the iterator to allow for calculating - /// the displacment of the iterator from following calls to [`Iterator::next`]. + /// the displacement of the iterator from following calls to [`Iterator::next`]. #[inline] #[unstable(feature = "peek_index", issue = "130711")] pub fn peek_index(&self) -> usize {