Skip to content
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

Add as_slice() to slice::IterMut and vec::Drain #58924

Merged
merged 4 commits into from Mar 9, 2019

Conversation

Projects
None yet
5 participants
@cuviper
Copy link
Member

cuviper commented Mar 4, 2019

In bluss/indexmap#88, we found that there was no easy way to implement
Debug for our IterMut and Drain iterators. Those are built on
slice::IterMut and vec::Drain, which implement Debug themselves,
but have no other way to access their data. With a new as_slice()
method, we can read the data and customize its presentation.

Add as_slice() to slice::IterMut and vec::Drain
In bluss/indexmap#88, we found that there was no easy way to implement
`Debug` for our `IterMut` and `Drain` iterators. Those are built on
`slice::IterMut` and `vec::Drain`, which implement `Debug` themselves,
but have no other way to access their data. With a new `as_slice()`
method, we can read the data and customize its presentation.
@rust-highfive

This comment has been minimized.

Copy link
Collaborator

rust-highfive commented Mar 4, 2019

r? @dtolnay

(rust_highfive has picked a reviewer for you, use r? to override)

@cuviper

This comment has been minimized.

Copy link
Member Author

cuviper commented Mar 4, 2019

FWIW, these could both support as_mut_slice() too, but I have no immediate use for that. I'm willing to add that for completeness if desired.

@dtolnay

dtolnay approved these changes Mar 5, 2019

Copy link
Member

dtolnay left a comment

Thanks! This looks good to me. Please open a tracking issue and add the number.

Show resolved Hide resolved src/libcore/slice/mod.rs Outdated
Show resolved Hide resolved src/libcore/slice/mod.rs Outdated
Show resolved Hide resolved src/libcore/slice/mod.rs Outdated
Show resolved Hide resolved src/libcore/slice/mod.rs Outdated
Show resolved Hide resolved src/libcore/slice/mod.rs Outdated
Show resolved Hide resolved src/libcore/slice/mod.rs Outdated
Show resolved Hide resolved src/libcore/slice/mod.rs Outdated

Centril and others added some commits Mar 6, 2019

Apply suggestions from code review
Co-Authored-By: cuviper <cuviper@gmail.com>
@cuviper

This comment has been minimized.

Copy link
Member Author

cuviper commented Mar 6, 2019

OK, I've hopefully addressed @Centril's feedback, and added tracking issue #58957.

@dtolnay

This comment has been minimized.

Copy link
Member

dtolnay commented Mar 6, 2019

@bors r+

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Mar 6, 2019

📌 Commit e478cad has been approved by dtolnay

Centril added a commit to Centril/rust that referenced this pull request Mar 9, 2019

Rollup merge of rust-lang#58924 - cuviper:more-as_slice, r=dtolnay
Add as_slice() to slice::IterMut and vec::Drain

In bluss/indexmap#88, we found that there was no easy way to implement
`Debug` for our `IterMut` and `Drain` iterators. Those are built on
`slice::IterMut` and `vec::Drain`, which implement `Debug` themselves,
but have no other way to access their data. With a new `as_slice()`
method, we can read the data and customize its presentation.

bors added a commit that referenced this pull request Mar 9, 2019

Auto merge of #59043 - Centril:rollup, r=Centril
Rollup of 14 pull requests

Successful merges:

 - #58518 (Use early unwraps instead of bubbling up errors just to unwrap in the end)
 - #58626 (rustdoc: add option to calculate "documentation coverage")
 - #58629 (rust-lldb: fix crash when printing empty string)
 - #58660 (MaybeUninit: add read_initialized, add examples)
 - #58670 (fixes #52482)
 - #58676 (look for python2 symlinks before bootstrap python)
 - #58679 (Refactor passes and pass execution to be more parallel)
 - #58743 (Add tests for several E-needstest issues)
 - #58750 (Make `Unique::as_ptr`, `NonNull::dangling` and `NonNull::cast` const)
 - #58762 (Mention `unwind(aborts)` in diagnostics for `#[unwind]`)
 - #58900 (Ignore should_panic tests on android)
 - #58924 (Add as_slice() to slice::IterMut and vec::Drain)
 - #58990 (Actually publish miri in the manifest)
 - #59018 (std: Delete a by-definition spuriously failing test)

Failed merges:

r? @ghost

Centril added a commit to Centril/rust that referenced this pull request Mar 9, 2019

Rollup merge of rust-lang#58924 - cuviper:more-as_slice, r=dtolnay
Add as_slice() to slice::IterMut and vec::Drain

In bluss/indexmap#88, we found that there was no easy way to implement
`Debug` for our `IterMut` and `Drain` iterators. Those are built on
`slice::IterMut` and `vec::Drain`, which implement `Debug` themselves,
but have no other way to access their data. With a new `as_slice()`
method, we can read the data and customize its presentation.

bors added a commit that referenced this pull request Mar 9, 2019

Auto merge of #59046 - Centril:rollup, r=Centril
Rollup of 13 pull requests

Successful merges:

 - #58518 (Use early unwraps instead of bubbling up errors just to unwrap in the end)
 - #58626 (rustdoc: add option to calculate "documentation coverage")
 - #58629 (rust-lldb: fix crash when printing empty string)
 - #58660 (MaybeUninit: add read_initialized, add examples)
 - #58670 (fixes #52482)
 - #58676 (look for python2 symlinks before bootstrap python)
 - #58679 (Refactor passes and pass execution to be more parallel)
 - #58743 (Add tests for several E-needstest issues)
 - #58750 (Make `Unique::as_ptr`, `NonNull::dangling` and `NonNull::cast` const)
 - #58762 (Mention `unwind(aborts)` in diagnostics for `#[unwind]`)
 - #58924 (Add as_slice() to slice::IterMut and vec::Drain)
 - #58990 (Actually publish miri in the manifest)
 - #59018 (std: Delete a by-definition spuriously failing test)

Failed merges:

r? @ghost

Centril added a commit to Centril/rust that referenced this pull request Mar 9, 2019

Rollup merge of rust-lang#58924 - cuviper:more-as_slice, r=dtolnay
Add as_slice() to slice::IterMut and vec::Drain

In bluss/indexmap#88, we found that there was no easy way to implement
`Debug` for our `IterMut` and `Drain` iterators. Those are built on
`slice::IterMut` and `vec::Drain`, which implement `Debug` themselves,
but have no other way to access their data. With a new `as_slice()`
method, we can read the data and customize its presentation.

bors added a commit that referenced this pull request Mar 9, 2019

Auto merge of #59050 - Centril:rollup, r=Centril
Rollup of 13 pull requests

Successful merges:

 - #58518 (Use early unwraps instead of bubbling up errors just to unwrap in the end)
 - #58626 (rustdoc: add option to calculate "documentation coverage")
 - #58629 (rust-lldb: fix crash when printing empty string)
 - #58660 (MaybeUninit: add read_initialized, add examples)
 - #58670 (fixes #52482)
 - #58676 (look for python2 symlinks before bootstrap python)
 - #58679 (Refactor passes and pass execution to be more parallel)
 - #58750 (Make `Unique::as_ptr`, `NonNull::dangling` and `NonNull::cast` const)
 - #58762 (Mention `unwind(aborts)` in diagnostics for `#[unwind]`)
 - #58924 (Add as_slice() to slice::IterMut and vec::Drain)
 - #58990 (Actually publish miri in the manifest)
 - #59018 (std: Delete a by-definition spuriously failing test)
 - #59045 (Expose new_sub_parser_from_file)

Failed merges:

r? @ghost

bors added a commit that referenced this pull request Mar 9, 2019

Auto merge of #59050 - Centril:rollup, r=Centril
Rollup of 13 pull requests

Successful merges:

 - #58518 (Use early unwraps instead of bubbling up errors just to unwrap in the end)
 - #58626 (rustdoc: add option to calculate "documentation coverage")
 - #58629 (rust-lldb: fix crash when printing empty string)
 - #58660 (MaybeUninit: add read_initialized, add examples)
 - #58670 (fixes #52482)
 - #58676 (look for python2 symlinks before bootstrap python)
 - #58679 (Refactor passes and pass execution to be more parallel)
 - #58750 (Make `Unique::as_ptr`, `NonNull::dangling` and `NonNull::cast` const)
 - #58762 (Mention `unwind(aborts)` in diagnostics for `#[unwind]`)
 - #58924 (Add as_slice() to slice::IterMut and vec::Drain)
 - #58990 (Actually publish miri in the manifest)
 - #59018 (std: Delete a by-definition spuriously failing test)
 - #59045 (Expose new_sub_parser_from_file)

Failed merges:

r? @ghost

@bors bors merged commit e478cad into rust-lang:master Mar 9, 2019

@dtolnay

This comment has been minimized.

Copy link
Member

dtolnay commented Mar 11, 2019

FYI @rust-lang/libs: two unstable methods:

impl<'a, T> slice::IterMut<'a, T> {
    pub fn as_slice(&self) -> &[T];
}

impl<'a, T> vec::Drain<'a, T> {
    pub fn as_slice(&self) -> &[T];
}

Tracking issue: #58957.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.