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

Support Iterating and Indexing on Nightly #1

Closed
Anders429 opened this issue Feb 7, 2021 · 4 comments
Closed

Support Iterating and Indexing on Nightly #1

Anders429 opened this issue Feb 7, 2021 · 4 comments
Labels
enhancement New feature or request

Comments

@Anders429
Copy link
Owner

It seems that supporting Iterating and Indexing on stable is tricky at the moment, due std::iter::Step and std::slice::SliceIndex having experimental APIs. For Step, I've considered using the step crate to accomplish the same purpose. The only issue is it forces users to implement step::Step if they want to iterate over a custom steppable range.

An alternative is to make iterating and indexing both available, in the same manner as they are implemented for the standard library range types, on nightly channels only. It seems that [autocfg](https://crates.io/crates/autocfg does not currently offer probing channels yet, although it may come in the future. rustc_version is another crate which can probe channels.

Another possibility is to lock iterating and indexing behind a nightly feature, allowing users to opt-in using cargo features.

@Anders429 Anders429 added the enhancement New feature or request label Feb 7, 2021
@Anders429
Copy link
Owner Author

Anders429 commented Mar 10, 2021

Iterating is completely implemented, including double ended iterator, fused iterator, exact size iterator, and trusted len.

It should be noted that released is blocked on either autocfg releasing support for feature probing or this crate switching to a different build assistant crate.

@Anders429
Copy link
Owner Author

Indexing will actually not have to be nightly-only. Turns out, SliceIndex is both not necessary for indexing and actually is useless since it is a sealed trait. The only thing to implement is Index and IndexMut for each type that should be indexable by these ranges. Note that these impls will only be available on rustc 1.41.0 and up.

@Anders429
Copy link
Owner Author

Almost all indexing is done. The only thing that may still be desired is implementing Index<RangeFromExclusive<usize>> for CStr (similar to Index<RangeFrom<usize>> for CStr, which is already implemented. However, CStr is only available on std, which may require feature-gating. There is also a cstr_core crate, which works on core, but involves bringing in another dependency and should therefore also be feature-gated. Possibly, a solution could be implementing both and allowing users to activate whatever implementation they need.

@Anders429
Copy link
Owner Author

This is now completely implemented in the 0.2.0 branch. Index<RangeFromExclusive<usize>> was implemented for CStr using autocfg::AutoCfg::probe_sysroot_crate() to check if std is available on the target before implementing. This means users don't have to fiddle around with features to get stuff to work; it just will.

I suppose if people want CStr on core, we can revisit this and add a feature flag. But for now, this should be sufficient.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant