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

cuviper
Copy link
Member

@cuviper cuviper commented Mar 4, 2019

In indexmap-rs/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.

In indexmap-rs/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
Copy link
Collaborator

r? @dtolnay

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

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 4, 2019
@cuviper
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.

Copy link
Member

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

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 Show resolved Hide resolved
@cuviper
Copy link
Member Author

cuviper commented Mar 6, 2019

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

@dtolnay
Copy link
Member

dtolnay commented Mar 6, 2019

@bors r+

@bors
Copy link
Contributor

bors commented Mar 6, 2019

📌 Commit e478cad has been approved by dtolnay

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 6, 2019
Centril added a commit to Centril/rust that referenced this pull request Mar 9, 2019
Add as_slice() to slice::IterMut and vec::Drain

In indexmap-rs/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.
Centril added a commit to Centril/rust that referenced this pull request Mar 9, 2019
Add as_slice() to slice::IterMut and vec::Drain

In indexmap-rs/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.
Centril added a commit to Centril/rust that referenced this pull request Mar 9, 2019
Add as_slice() to slice::IterMut and vec::Drain

In indexmap-rs/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
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
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.

@cuviper cuviper deleted the more-as_slice branch March 27, 2019 22:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants