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

Tracking issue for converting slice iterators to slices #27775

Closed
alexcrichton opened this issue Aug 12, 2015 · 10 comments · Fixed by #28339
Closed

Tracking issue for converting slice iterators to slices #27775

alexcrichton opened this issue Aug 12, 2015 · 10 comments · Fixed by #28339
Labels
B-unstable Blocker: Implemented in the nightly compiler and unstable. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Milestone

Comments

@alexcrichton
Copy link
Member

This is a tracking issue for the unstable iter_to_slice feature in the standard library. The into_vec adaptor for vec::IntoIter was recently removed, and these may also want to be removed. It's somewhat unclear how useful it is to have iterators enhanced with this kind of functionality.

@alexcrichton alexcrichton added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. B-unstable Blocker: Implemented in the nightly compiler and unstable. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. labels Aug 12, 2015
@SimonSapin
Copy link
Contributor

I kinda like this method, though I admit I’ve never actually used it :)

This method is probably the simplest way to expose safely something isomorphic to the private fields of the slice iterators (a pair of pointers). All sorts of interesting things that we have not foreseen could be built on top of it outside of std. (Like maybe finding the line number of the current iterator position for error reporting in an interator-based parser with subslice_offset. But whether that specific example makes sense is besides the point.)

If this method is removed without a replacement, there is no way to get at the full information that is carried by slice::Iter. (Without crazy-unsafe transmutes or pointer offseting that guess the struct layout.)

On the other hand, what’s the cost of keeping it? Are there issues with it?

@alexcrichton
Copy link
Member Author

This feature is now entering its final comment period for deprecation

@alexcrichton alexcrichton added the final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. label Aug 14, 2015
@aturon
Copy link
Member

aturon commented Aug 14, 2015

Note that IntoVec was removed not because it wasn't wanted, but because drain provided a superior replacement.

I agree with @SimonSapin that these methods seem harmless and appealing... even if, like @SimonSapin, I haven't used them myself :)

@bluss
Copy link
Member

bluss commented Aug 14, 2015

@aturon, I disagree because IntoIter & into vec are useful where drain isn't. I've got a usecase for IntoIter and I'd like to cycle out the IntoIterators and use their allocations again, after they are emptied..

@aturon
Copy link
Member

aturon commented Aug 14, 2015

@bluss Right, but my point is, IntoIter was removed, but that's not analogous to removing the slice functionality here, since we don't have anything akin to drain.

@bluss
Copy link
Member

bluss commented Aug 14, 2015

@SimonSapin I like your viewpoint. Going back and forth between slices and iterators allows working with them in a kind of random access way, without having to separately count the steps you do in "iterator mode".

@jan-hudec
Copy link

Where these functions would be extremely useful is for strings, but I don't see them there.

Basically many string operations require &str, but other are much easier on iterators. Not being able to convert between those representations means a lot of duplicate information needs to be kept and one often needs to resort to char_indices, which is a bit unwieldy. Moreover, often the slice from start to iterator/subslice is needed, e.g. to be passed to std::str::FromStr::from_str. This could be built from as_slice for Chars and subslice_index, but a special function would have the advantage that it could skip the is_char_boundary check, because the slice/iterator were (unless unsafe was used) checked.

@bluss
Copy link
Member

bluss commented Aug 19, 2015

run_utf8_validation_iterator shows a use case, but that particular function could just take a &[u8] instead of an iterator. I agree with @jan-hudec, some of my algorithms could absolutely be simplified with to_str() available on the chars iterator.

@SimonSapin
Copy link
Contributor

I’ll submit a PR to add it. to_str or as_str?

@bluss
Copy link
Member

bluss commented Aug 19, 2015

I guess as_str() if we keep the as_slice method on slice iterators.

alexcrichton added a commit to alexcrichton/rust that referenced this issue Sep 13, 2015
The FCP is coming to a close and 1.4 is coming out soon, so this brings in the
libs team decision for all library features this cycle.

Stabilized APIs:

* `<Box<str>>::into_string`
* `Arc::downgrade`
* `Arc::get_mut`
* `Arc::make_mut`
* `Arc::try_unwrap`
* `Box::from_raw`
* `Box::into_raw`
* `CStr::to_str`
* `CStr::to_string_lossy`
* `CString::from_raw`
* `CString::into_raw`
* `IntoRawFd::into_raw_fd`
* `IntoRawFd`
* `IntoRawHandle::into_raw_handle`
* `IntoRawHandle`
* `IntoRawSocket::into_raw_socket`
* `IntoRawSocket`
* `Rc::downgrade`
* `Rc::get_mut`
* `Rc::make_mut`
* `Rc::try_unwrap`
* `Result::expect`
* `String::into_boxed_slice`
* `TcpSocket::read_timeout`
* `TcpSocket::set_read_timeout`
* `TcpSocket::set_write_timeout`
* `TcpSocket::write_timeout`
* `UdpSocket::read_timeout`
* `UdpSocket::set_read_timeout`
* `UdpSocket::set_write_timeout`
* `UdpSocket::write_timeout`
* `Vec::append`
* `Vec::split_off`
* `VecDeque::append`
* `VecDeque::retain`
* `VecDeque::split_off`
* `rc::Weak::upgrade`
* `rc::Weak`
* `slice::Iter::as_slice`
* `slice::IterMut::into_slice`
* `str::CharIndices::as_str`
* `str::Chars::as_str`
* `str::split_at_mut`
* `str::split_at`
* `sync::Weak::upgrade`
* `sync::Weak`
* `thread::park_timeout`
* `thread::sleep`

Deprecated APIs

* `BTreeMap::with_b`
* `BTreeSet::with_b`
* `Option::as_mut_slice`
* `Option::as_slice`
* `Result::as_mut_slice`
* `Result::as_slice`
* `f32::from_str_radix`
* `f64::from_str_radix`

Closes rust-lang#27277
Closes rust-lang#27718
Closes rust-lang#27736
Closes rust-lang#27764
Closes rust-lang#27765
Closes rust-lang#27766
Closes rust-lang#27767
Closes rust-lang#27768
Closes rust-lang#27769
Closes rust-lang#27771
Closes rust-lang#27773
Closes rust-lang#27775
Closes rust-lang#27776
Closes rust-lang#27785
Closes rust-lang#27792
Closes rust-lang#27795
Closes rust-lang#27797
bors added a commit that referenced this issue Sep 13, 2015
The FCP is coming to a close and 1.4 is coming out soon, so this brings in the
libs team decision for all library features this cycle.

Stabilized APIs:

* `<Box<str>>::into_string`
* `Arc::downgrade`
* `Arc::get_mut`
* `Arc::make_mut`
* `Arc::try_unwrap`
* `Box::from_raw`
* `Box::into_raw`
* `CStr::to_str`
* `CStr::to_string_lossy`
* `CString::from_raw`
* `CString::into_raw`
* `IntoRawFd::into_raw_fd`
* `IntoRawFd`
* `IntoRawHandle::into_raw_handle`
* `IntoRawHandle`
* `IntoRawSocket::into_raw_socket`
* `IntoRawSocket`
* `Rc::downgrade`
* `Rc::get_mut`
* `Rc::make_mut`
* `Rc::try_unwrap`
* `Result::expect`
* `String::into_boxed_slice`
* `TcpSocket::read_timeout`
* `TcpSocket::set_read_timeout`
* `TcpSocket::set_write_timeout`
* `TcpSocket::write_timeout`
* `UdpSocket::read_timeout`
* `UdpSocket::set_read_timeout`
* `UdpSocket::set_write_timeout`
* `UdpSocket::write_timeout`
* `Vec::append`
* `Vec::split_off`
* `VecDeque::append`
* `VecDeque::retain`
* `VecDeque::split_off`
* `rc::Weak::upgrade`
* `rc::Weak`
* `slice::Iter::as_slice`
* `slice::IterMut::into_slice`
* `str::CharIndices::as_str`
* `str::Chars::as_str`
* `str::split_at_mut`
* `str::split_at`
* `sync::Weak::upgrade`
* `sync::Weak`
* `thread::park_timeout`
* `thread::sleep`

Deprecated APIs

* `BTreeMap::with_b`
* `BTreeSet::with_b`
* `Option::as_mut_slice`
* `Option::as_slice`
* `Result::as_mut_slice`
* `Result::as_slice`
* `f32::from_str_radix`
* `f64::from_str_radix`

Closes #27277
Closes #27718
Closes #27736
Closes #27764
Closes #27765
Closes #27766
Closes #27767
Closes #27768
Closes #27769
Closes #27771
Closes #27773
Closes #27775
Closes #27776
Closes #27785
Closes #27792
Closes #27795
Closes #27797
@steveklabnik steveklabnik added this to the 1.3 milestone Sep 18, 2015
@steveklabnik steveklabnik modified the milestones: 1.4, 1.3 Oct 1, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
B-unstable Blocker: Implemented in the nightly compiler and unstable. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants