From 9599c0066f4c4ad180e5217bc9ed3b716a605587 Mon Sep 17 00:00:00 2001 From: okakatsuo Date: Thu, 8 Jan 2026 04:37:48 +0900 Subject: [PATCH 1/5] =?UTF-8?q?std::vec::IntoIter=20=E3=81=AE=E3=83=AA?= =?UTF-8?q?=E3=83=95=E3=82=A1=E3=83=AC=E3=83=B3=E3=82=B9=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/vec/IntoIter.md | 197 ++++++++++++++++++++++++++++++++++++++++++++ src/vec/about.md | 2 +- 2 files changed, 198 insertions(+), 1 deletion(-) create mode 100644 src/vec/IntoIter.md diff --git a/src/vec/IntoIter.md b/src/vec/IntoIter.md new file mode 100644 index 0000000..05544de --- /dev/null +++ b/src/vec/IntoIter.md @@ -0,0 +1,197 @@ +# 構造体 `std::vec::IntoIter` + +```rust,ignore +pub struct IntoIter +where + A: std::alloc::Allocator +{ /* private fields */ } +``` + +## 解説 + +ベクターの所有権を放棄し、各要素を順に返すイテレータ。 +`Vec`の`into_iter`メソッド(`IntoIterator`トレイトの実装)によって作成される。 + +## 例 + +```rust +let v = vec![0, 1, 2]; +// vの所有権がiterに移動する +let iter: std::vec::IntoIter = v.into_iter(); + +// 所有権を持っているので、要素を直接消費できる +for x in iter { + println!("{}", x); +} +``` + +## 実装 + +```rust,ignore +impl IntoIter +where + A: std::alloc::Allocator +{ + pub fn as_slice(&self) -> &[T]; + + pub fn as_mut_slice(&mut self) -> &mut [T]; + + // nightly-only + pub fn allocator(&self) -> &A; +} +``` + +### `as_slice` + +まだ消費されていない要素をスライスとして返す関数。 + +```rust +let vec = vec!['a', 'b', 'c']; +let mut into_iter = vec.into_iter(); + +// 最初はすべての要素が見える +assert_eq!(into_iter.as_slice(), &['a', 'b', 'c']); + +// 1つ消費する +let _ = into_iter.next().unwrap(); + +// 残りの要素が返される +assert_eq!(into_iter.as_slice(), &['b', 'c']); +``` + +### `as_mut_slice` + +まだ消費されていない要素を可変スライスとして返す関数。 + +```rust +let vec = vec!['a', 'b', 'c']; +let mut into_iter = vec.into_iter(); + +// 消費前のスライスを書き換える +into_iter.as_mut_slice()[2] = 'z'; + +assert_eq!(into_iter.next().unwrap(), 'a'); +assert_eq!(into_iter.next().unwrap(), 'b'); +assert_eq!(into_iter.next().unwrap(), 'z'); // 書き換えた値が返る +``` + +### `allocator` + +> [!NOTE] +> nightlyでのみ使用可能 + +内部で使用しているアロケーターへの参照を返す関数。 + +## トレイト実装 + +### `AsRef` + +```rust,ignore +impl AsRef<[T]> for IntoIter +where + A: std::alloc::Allocator +{ /* trait methods */ } +``` + +### `Clone` + +```rust,ignore +impl Clone for IntoIter +where + T: Clone, + A: std::alloc::Allocator + Clone +{ /* trait methods */ } +``` + +### `std::fmt::Debug` + +```rust,ignore +impl std::fmt::Debug for IntoIter +where + T: std::fmt::Debug, + A: std::alloc::Allocator +{ /* trait methods */ } +``` + +### `Default` + +```rust,ignore +impl Default for IntoIter +where + A: std::alloc::Allocator + Default +{ /* trait methods */ } +``` + +### `DoubleEndedIterator` + +```rust,ignore +impl DoubleEndedIterator for IntoIter +where + A: std::alloc::Allocator +{ /* trait methods */ } +``` + +### `Drop` + +```rust,ignore +impl Drop for IntoIter +where + A: std::alloc::Allocator +{ /* trait methods */ } +``` + +### `ExactSizeIterator` + +```rust,ignore +impl ExactSizeIterator for IntoIter +where + A: std::alloc::Allocator +{ /* trait methods */ } +``` + +### `Iterator` + +```rust,ignore +impl Iterator for IntoIter +where + A: std::alloc::Allocator +{ /* trait methods */ } +``` + +### `std::iter::FusedIterator` + +```rust,ignore +impl std::iter::FusedIterator for IntoIter +where + A: std::alloc::Allocator +{ /* trait methods */ } +``` + +### `Send` + +```rust,ignore +impl Send for IntoIter +where + T: Send, + A: std::alloc::Allocator + Send +{ /* trait methods */ } +``` + +### `Sync` + +```rust,ignore +impl Sync for IntoIter +where + T: Sync, + A: std::alloc::Allocator + Sync +{ /* trait methods */ } +``` + +### `std::iter::TrustedLen` + +```rust,ignore +impl std::iter::TrustedLen for IntoIter +where + A: std::alloc::Allocator +{ /* trait methods */ } +``` diff --git a/src/vec/about.md b/src/vec/about.md index e731b25..d6755b2 100644 --- a/src/vec/about.md +++ b/src/vec/about.md @@ -17,5 +17,5 @@ | 名前 | 説明 | 種類 | | --- | --- | --- | | [`Drain`](./Drain.md) | ベクター内の指定された区間を削除し、取り除かれた要素を与えるイテレータ | 構造体 | -| `IntoIter` | ベクター内の指定された区間の所有権を奪うイテレータ | 構造体 | +| [`IntoIter`](./IntoIter.md) | ベクター内の指定された区間の所有権を奪うイテレータ | 構造体 | | `Splite` | ベクター内の指定された区間を与えられたイテレーターと入れ替え、元の要素を返すイテレータ | 構造体 | From 03b1e16ca7b25f3310faa9e7e16deb6edaa7e026 Mon Sep 17 00:00:00 2001 From: okakatsuo Date: Thu, 8 Jan 2026 04:45:27 +0900 Subject: [PATCH 2/5] =?UTF-8?q?=E3=82=BF=E3=82=A4=E3=83=9D=E3=81=AE?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/vec/Drain.md | 2 +- src/vec/about.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vec/Drain.md b/src/vec/Drain.md index 033b995..9722997 100644 --- a/src/vec/Drain.md +++ b/src/vec/Drain.md @@ -206,7 +206,7 @@ where { /* trait methods */ } ``` -### `Interator` +### `Iterator` ```rust,ignore impl Iterator for Drain<'_, T, A> diff --git a/src/vec/about.md b/src/vec/about.md index d6755b2..03114aa 100644 --- a/src/vec/about.md +++ b/src/vec/about.md @@ -18,4 +18,4 @@ | --- | --- | --- | | [`Drain`](./Drain.md) | ベクター内の指定された区間を削除し、取り除かれた要素を与えるイテレータ | 構造体 | | [`IntoIter`](./IntoIter.md) | ベクター内の指定された区間の所有権を奪うイテレータ | 構造体 | -| `Splite` | ベクター内の指定された区間を与えられたイテレーターと入れ替え、元の要素を返すイテレータ | 構造体 | +| `Splice` | ベクター内の指定された区間を与えられたイテレーターと入れ替え、元の要素を返すイテレータ | 構造体 | From a7266df06018a685ffbb576eac0382a2746cf3dd Mon Sep 17 00:00:00 2001 From: okakatsuo Date: Thu, 8 Jan 2026 04:45:27 +0900 Subject: [PATCH 3/5] =?UTF-8?q?=E3=82=BF=E3=82=A4=E3=83=9D=E3=81=AE?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/vec/Drain.md | 2 +- src/vec/about.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vec/Drain.md b/src/vec/Drain.md index 033b995..9722997 100644 --- a/src/vec/Drain.md +++ b/src/vec/Drain.md @@ -206,7 +206,7 @@ where { /* trait methods */ } ``` -### `Interator` +### `Iterator` ```rust,ignore impl Iterator for Drain<'_, T, A> diff --git a/src/vec/about.md b/src/vec/about.md index d6755b2..03114aa 100644 --- a/src/vec/about.md +++ b/src/vec/about.md @@ -18,4 +18,4 @@ | --- | --- | --- | | [`Drain`](./Drain.md) | ベクター内の指定された区間を削除し、取り除かれた要素を与えるイテレータ | 構造体 | | [`IntoIter`](./IntoIter.md) | ベクター内の指定された区間の所有権を奪うイテレータ | 構造体 | -| `Splite` | ベクター内の指定された区間を与えられたイテレーターと入れ替え、元の要素を返すイテレータ | 構造体 | +| `Splice` | ベクター内の指定された区間を与えられたイテレーターと入れ替え、元の要素を返すイテレータ | 構造体 | From 227f8350fbcb740864a3ea5a922a64e7cfa89560 Mon Sep 17 00:00:00 2001 From: hinshi <105423175+hinshiba@users.noreply.github.com> Date: Sun, 11 Jan 2026 21:16:42 +0900 Subject: [PATCH 4/5] =?UTF-8?q?fix:=20=E3=82=B3=E3=83=B3=E3=83=95=E3=83=AA?= =?UTF-8?q?=E3=82=AF=E3=83=88=E5=AF=BE=E5=BF=9C=E6=99=82=E3=81=AE=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3=E6=BC=8F=E3=82=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hinshi <105423175+hinshiba@users.noreply.github.com> --- src/vec/about.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vec/about.md b/src/vec/about.md index 79ce310..36e53c4 100644 --- a/src/vec/about.md +++ b/src/vec/about.md @@ -23,7 +23,7 @@ Rust 1.0.0 ~ 説明は簡単なものでよい。 --> | 名前 | 説明 | -| --- | --- | --- | +| --- | --- | | [`Drain`](./Drain.md) | ベクター内の指定された区間を削除し、取り除かれた要素を与えるイテレータ | | [`IntoIter`](./IntoIter.md) | ベクター内の指定された区間の所有権を奪うイテレータ | | `Splice` | ベクター内の指定された区間を与えられたイテレーターと入れ替え、元の要素を返すイテレータ | From 8261de9a28ac2ef4da492e361ba4947e58eb6586 Mon Sep 17 00:00:00 2001 From: okakatsuo Date: Sun, 11 Jan 2026 21:21:19 +0900 Subject: [PATCH 5/5] =?UTF-8?q?docs:=20SUMMARY.md=20=E3=81=AB=20IntoIter?= =?UTF-8?q?=20=E3=81=B8=E3=81=AE=E3=83=AA=E3=83=B3=E3=82=AF=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/SUMMARY.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 7ec65f2..53873df 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -8,4 +8,4 @@ - [std::vec](./vec/about.md) - [Drain](./vec/Drain.md) - + - [IntoIter](./vec/IntoIter.md)