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 methods to go from a slice iterators to a slice. #18966

Merged
merged 1 commit into from
Nov 25, 2014

Conversation

huonw
Copy link
Member

@huonw huonw commented Nov 15, 2014

A slice iterator is isomorphic to a slice, just with a slightly
different form: storing start and end pointers rather than start pointer
and length. This patch reflects this by making converting between them
as easy as iter.as_slice() (or even iter[] if the shorter lifetime
is ok). That is, slice.iter().as_slice() == slice.

r? @aturon

@rust-highfive
Copy link
Collaborator

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!

@aturon
Copy link
Member

aturon commented Nov 15, 2014

This looks good, but I'm curious why you chose not to implement explicit as_slice and as_mut_slice methods on MutItems that work on borrows (i.e. shorter lifetimes, like the notation does)?

Ultimately, if the [] notation sticks around we will probably remove as_slice, so in the long run it's a moot point, but I wanted to get your thinking.

@huonw
Copy link
Member Author

huonw commented Nov 15, 2014

Purely to avoid duplication between the notation and explicit methods.

@aturon
Copy link
Member

aturon commented Nov 15, 2014

@huonw Can you add #[experimental] attributes to the trait impls and new methods? Otherwise, r=me.

A slice iterator is isomorphic to a slice, just with a slightly
different form: storing start and end pointers rather than start pointer
and length. This patch reflects this by making converting between them
as easy as `iter.as_slice()` (or even `iter[]` if the shorter lifetime
is ok). That is, `slice.iter().as_slice() == slice`.
bors added a commit that referenced this pull request Nov 25, 2014
A slice iterator is isomorphic to a slice, just with a slightly
different form: storing start and end pointers rather than start pointer
and length. This patch reflects this by making converting between them
as easy as `iter.as_slice()` (or even `iter[]` if the shorter lifetime
is ok). That is, `slice.iter().as_slice() == slice`.

r? @aturon
@bors bors closed this Nov 25, 2014
@bors bors merged commit b86a780 into rust-lang:master Nov 25, 2014
lnicola added a commit to lnicola/rust that referenced this pull request Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants