-
Notifications
You must be signed in to change notification settings - Fork 4
リファレンス追加: std::vec::IntoIter および vecモジュールの誤字修正 #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
okakatsuo
wants to merge
8
commits into
Rust-Developers-JP:main
Choose a base branch
from
okakatsuo:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9599c00
std::vec::IntoIter のリファレンスを追加
okakatsuo 03b1e16
タイポの修正
okakatsuo a7266df
タイポの修正
okakatsuo a6c08b5
Merge branch 'main' of https://github.com/okakatsuo/rsdocsjp
okakatsuo 6c02504
Merge branch 'main' into main
hinshiba 227f835
fix: コンフリクト対応時の修正漏れ
hinshiba 8261de9
docs: SUMMARY.md に IntoIter へのリンクを追加
okakatsuo 65b2d00
Merge branch 'main' of https://github.com/okakatsuo/rsdocsjp
okakatsuo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,4 +8,4 @@ | |
|
|
||
| - [std::vec](./vec/about.md) | ||
| - [Drain](./vec/Drain.md) | ||
|
|
||
| - [IntoIter](./vec/IntoIter.md) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,197 @@ | ||
| # 構造体 `std::vec::IntoIter` | ||
|
|
||
| ```rust,ignore | ||
| pub struct IntoIter<T, A = std::alloc::Global> | ||
| 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<i32> = v.into_iter(); | ||
|
|
||
| // 所有権を持っているので、要素を直接消費できる | ||
| for x in iter { | ||
| println!("{}", x); | ||
| } | ||
| ``` | ||
|
|
||
| ## 実装 | ||
|
|
||
| ```rust,ignore | ||
| impl<T, A> IntoIter<T, A> | ||
| 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<T, A> AsRef<[T]> for IntoIter<T, A> | ||
| where | ||
| A: std::alloc::Allocator | ||
| { /* trait methods */ } | ||
| ``` | ||
|
|
||
| ### `Clone` | ||
|
|
||
| ```rust,ignore | ||
| impl<T, A> Clone for IntoIter<T, A> | ||
| where | ||
| T: Clone, | ||
| A: std::alloc::Allocator + Clone | ||
| { /* trait methods */ } | ||
| ``` | ||
|
|
||
| ### `std::fmt::Debug` | ||
|
|
||
| ```rust,ignore | ||
| impl<T, A> std::fmt::Debug for IntoIter<T, A> | ||
| where | ||
| T: std::fmt::Debug, | ||
| A: std::alloc::Allocator | ||
| { /* trait methods */ } | ||
| ``` | ||
|
|
||
| ### `Default` | ||
|
|
||
| ```rust,ignore | ||
| impl<T, A> Default for IntoIter<T, A> | ||
| where | ||
| A: std::alloc::Allocator + Default | ||
| { /* trait methods */ } | ||
| ``` | ||
|
|
||
| ### `DoubleEndedIterator` | ||
|
|
||
| ```rust,ignore | ||
| impl<T, A> DoubleEndedIterator for IntoIter<T, A> | ||
| where | ||
| A: std::alloc::Allocator | ||
| { /* trait methods */ } | ||
| ``` | ||
|
|
||
| ### `Drop` | ||
|
|
||
| ```rust,ignore | ||
| impl<T, A> Drop for IntoIter<T, A> | ||
| where | ||
| A: std::alloc::Allocator | ||
| { /* trait methods */ } | ||
| ``` | ||
|
|
||
| ### `ExactSizeIterator` | ||
|
|
||
| ```rust,ignore | ||
| impl<T, A> ExactSizeIterator for IntoIter<T, A> | ||
| where | ||
| A: std::alloc::Allocator | ||
| { /* trait methods */ } | ||
| ``` | ||
|
|
||
| ### `Iterator` | ||
|
|
||
| ```rust,ignore | ||
| impl<T, A> Iterator for IntoIter<T, A> | ||
| where | ||
| A: std::alloc::Allocator | ||
| { /* trait methods */ } | ||
| ``` | ||
|
|
||
| ### `std::iter::FusedIterator` | ||
|
|
||
| ```rust,ignore | ||
| impl<T, A> std::iter::FusedIterator for IntoIter<T, A> | ||
| where | ||
| A: std::alloc::Allocator | ||
| { /* trait methods */ } | ||
| ``` | ||
|
|
||
| ### `Send` | ||
|
|
||
| ```rust,ignore | ||
| impl<T, A> Send for IntoIter<T, A> | ||
| where | ||
| T: Send, | ||
| A: std::alloc::Allocator + Send | ||
| { /* trait methods */ } | ||
| ``` | ||
|
|
||
| ### `Sync` | ||
|
|
||
| ```rust,ignore | ||
| impl<T, A> Sync for IntoIter<T, A> | ||
| where | ||
| T: Sync, | ||
| A: std::alloc::Allocator + Sync | ||
| { /* trait methods */ } | ||
| ``` | ||
|
|
||
| ### `std::iter::TrustedLen` | ||
|
|
||
| ```rust,ignore | ||
| impl<T, A> std::iter::TrustedLen for IntoIter<T, A> | ||
| where | ||
| A: std::alloc::Allocator | ||
| { /* trait methods */ } | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
この例はやや誤解を招くように思えます.
ここで要素を消費しているのは
forだと思いますが,println!()があるのでそちらが消費するように見えてしまうと思うのですが,どうでしょうか?もちろんforにコメントがついていると言われればそれまでですが