-
Notifications
You must be signed in to change notification settings - Fork 13.3k
docs: Add example to Iterator::take
with by_ref
#139780
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
Conversation
If you want to logically split an iterator after `n` items, you might first discover `take`. Before this change, you'd find that `take` consumes the iterator, and you'd probably be stuck. The answer involves `by_ref`, but that's hard to discover, especially since `by_ref` is a bit abstract and `Iterator` has many methods. After this change, you'd see the example showing `take` along with `by_ref`, which allows you to continue using the rest of the iterator. `by_ref` had a good example involving `take` already, so this change just duplicates that existing example under `take`.
rustbot has assigned @workingjubilee. Use |
Fun fact: the last time I submitted a PR to Rust was in 2013! https://github.com/rust-lang/rust/pulls?q=author%3Aongardie |
This reminds me of a semi-recent proposal (not an RFC yet, just kicking the idea around so far) to add a postfix operator in the style of In lieu of that sort of thing, however, this seems like a fine addition to the docs! Welcome back. @bors r+ rollup |
Thanks! It'd definitely be nicer to not have to do anything special here, and if/when that day comes, we'll get to update the comment :) |
…ple, r=workingjubilee docs: Add example to `Iterator::take` with `by_ref` If you want to logically split an iterator after `n` items, you might first discover `take`. Before this change, you'd find that `take` consumes the iterator, and you'd probably be stuck. The answer involves `by_ref`, but that's hard to discover, especially since `by_ref` is a bit abstract and `Iterator` has many methods. After this change, you'd see the example showing `take` along with `by_ref`, which allows you to continue using the rest of the iterator. `by_ref` had a good example involving `take` already, so this change just duplicates that existing example under `take`.
Rollup of 11 pull requests Successful merges: - rust-lang#134034 (handle paren in macro expand for let-init-else expr) - rust-lang#138703 (chore: remove redundant words in comment) - rust-lang#139186 (Refactor `diy_float`) - rust-lang#139343 (Change signature of File::try_lock and File::try_lock_shared) - rust-lang#139780 (docs: Add example to `Iterator::take` with `by_ref`) - rust-lang#139802 (Fix some grammar errors and hyperlinks in doc for `trait Allocator`) - rust-lang#140034 (simd_select_bitmask: the 'padding' bits in the mask are just ignored) - rust-lang#140062 (std: mention `remove_dir_all` can emit `DirectoryNotEmpty` when concurrently written into) - rust-lang#140485 (Optimize the codegen for `Span::from_expansion`) - rust-lang#140505 (linker: Quote symbol names in .def files) - rust-lang#140521 (interpret: better error message for out-of-bounds pointer arithmetic and accesses) r? `@ghost` `@rustbot` modify labels: rollup
…ple, r=workingjubilee docs: Add example to `Iterator::take` with `by_ref` If you want to logically split an iterator after `n` items, you might first discover `take`. Before this change, you'd find that `take` consumes the iterator, and you'd probably be stuck. The answer involves `by_ref`, but that's hard to discover, especially since `by_ref` is a bit abstract and `Iterator` has many methods. After this change, you'd see the example showing `take` along with `by_ref`, which allows you to continue using the rest of the iterator. `by_ref` had a good example involving `take` already, so this change just duplicates that existing example under `take`.
Rollup of 10 pull requests Successful merges: - rust-lang#134034 (handle paren in macro expand for let-init-else expr) - rust-lang#138703 (chore: remove redundant words in comment) - rust-lang#139186 (Refactor `diy_float`) - rust-lang#139343 (Change signature of File::try_lock and File::try_lock_shared) - rust-lang#139780 (docs: Add example to `Iterator::take` with `by_ref`) - rust-lang#139802 (Fix some grammar errors and hyperlinks in doc for `trait Allocator`) - rust-lang#140034 (simd_select_bitmask: the 'padding' bits in the mask are just ignored) - rust-lang#140062 (std: mention `remove_dir_all` can emit `DirectoryNotEmpty` when concurrently written into) - rust-lang#140485 (Optimize the codegen for `Span::from_expansion`) - rust-lang#140521 (interpret: better error message for out-of-bounds pointer arithmetic and accesses) r? `@ghost` `@rustbot` modify labels: rollup
…ple, r=workingjubilee docs: Add example to `Iterator::take` with `by_ref` If you want to logically split an iterator after `n` items, you might first discover `take`. Before this change, you'd find that `take` consumes the iterator, and you'd probably be stuck. The answer involves `by_ref`, but that's hard to discover, especially since `by_ref` is a bit abstract and `Iterator` has many methods. After this change, you'd see the example showing `take` along with `by_ref`, which allows you to continue using the rest of the iterator. `by_ref` had a good example involving `take` already, so this change just duplicates that existing example under `take`.
…llaumeGomez Rollup of 12 pull requests Successful merges: - rust-lang#138703 (chore: remove redundant words in comment) - rust-lang#139186 (Refactor `diy_float`) - rust-lang#139343 (Change signature of File::try_lock and File::try_lock_shared) - rust-lang#139780 (docs: Add example to `Iterator::take` with `by_ref`) - rust-lang#139802 (Fix some grammar errors and hyperlinks in doc for `trait Allocator`) - rust-lang#140034 (simd_select_bitmask: the 'padding' bits in the mask are just ignored) - rust-lang#140062 (std: mention `remove_dir_all` can emit `DirectoryNotEmpty` when concurrently written into) - rust-lang#140420 (rustdoc: Fix doctest heuristic for main fn wrapping) - rust-lang#140460 (Fix handling of LoongArch target features not supported by LLVM 19) - rust-lang#140538 (rustc-dev-guide subtree update) - rust-lang#140552 (allow `#[rustc_std_internal_symbol]` in combination with `#[naked]`) - rust-lang#140556 (Improve error output in case `nodejs` or `npm` is not installed for rustdoc-gui test suite) r? `@ghost` `@rustbot` modify labels: rollup
…llaumeGomez Rollup of 12 pull requests Successful merges: - rust-lang#138703 (chore: remove redundant words in comment) - rust-lang#139186 (Refactor `diy_float`) - rust-lang#139780 (docs: Add example to `Iterator::take` with `by_ref`) - rust-lang#139802 (Fix some grammar errors and hyperlinks in doc for `trait Allocator`) - rust-lang#140034 (simd_select_bitmask: the 'padding' bits in the mask are just ignored) - rust-lang#140062 (std: mention `remove_dir_all` can emit `DirectoryNotEmpty` when concurrently written into) - rust-lang#140420 (rustdoc: Fix doctest heuristic for main fn wrapping) - rust-lang#140460 (Fix handling of LoongArch target features not supported by LLVM 19) - rust-lang#140538 (rustc-dev-guide subtree update) - rust-lang#140544 (Clean up "const" situation in format_args!(). ) - rust-lang#140552 (allow `#[rustc_std_internal_symbol]` in combination with `#[naked]`) - rust-lang#140556 (Improve error output in case `nodejs` or `npm` is not installed for rustdoc-gui test suite) r? `@ghost` `@rustbot` modify labels: rollup
…ple, r=workingjubilee docs: Add example to `Iterator::take` with `by_ref` If you want to logically split an iterator after `n` items, you might first discover `take`. Before this change, you'd find that `take` consumes the iterator, and you'd probably be stuck. The answer involves `by_ref`, but that's hard to discover, especially since `by_ref` is a bit abstract and `Iterator` has many methods. After this change, you'd see the example showing `take` along with `by_ref`, which allows you to continue using the rest of the iterator. `by_ref` had a good example involving `take` already, so this change just duplicates that existing example under `take`.
…uillaumeGomez Rollup of 12 pull requests Successful merges: - rust-lang#138703 (chore: remove redundant words in comment) - rust-lang#139186 (Refactor `diy_float`) - rust-lang#139780 (docs: Add example to `Iterator::take` with `by_ref`) - rust-lang#139802 (Fix some grammar errors and hyperlinks in doc for `trait Allocator`) - rust-lang#140034 (simd_select_bitmask: the 'padding' bits in the mask are just ignored) - rust-lang#140062 (std: mention `remove_dir_all` can emit `DirectoryNotEmpty` when concurrently written into) - rust-lang#140420 (rustdoc: Fix doctest heuristic for main fn wrapping) - rust-lang#140460 (Fix handling of LoongArch target features not supported by LLVM 19) - rust-lang#140538 (rustc-dev-guide subtree update) - rust-lang#140544 (Clean up "const" situation in format_args!(). ) - rust-lang#140552 (allow `#[rustc_std_internal_symbol]` in combination with `#[naked]`) - rust-lang#140556 (Improve error output in case `nodejs` or `npm` is not installed for rustdoc-gui test suite) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#139780 - ongardie:iterator-take-by_ref-example, r=workingjubilee docs: Add example to `Iterator::take` with `by_ref` If you want to logically split an iterator after `n` items, you might first discover `take`. Before this change, you'd find that `take` consumes the iterator, and you'd probably be stuck. The answer involves `by_ref`, but that's hard to discover, especially since `by_ref` is a bit abstract and `Iterator` has many methods. After this change, you'd see the example showing `take` along with `by_ref`, which allows you to continue using the rest of the iterator. `by_ref` had a good example involving `take` already, so this change just duplicates that existing example under `take`.
If you want to logically split an iterator after
n
items, you might first discovertake
. Before this change, you'd find thattake
consumes the iterator, and you'd probably be stuck. The answer involvesby_ref
, but that's hard to discover, especially sinceby_ref
is a bit abstract andIterator
has many methods.After this change, you'd see the example showing
take
along withby_ref
, which allows you to continue using the rest of the iterator.by_ref
had a good example involvingtake
already, so this change just duplicates that existing example undertake
.