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

Implement From<RangeInclusive> for Uniform #556

Closed
vks opened this issue Jul 16, 2018 · 7 comments
Closed

Implement From<RangeInclusive> for Uniform #556

vks opened this issue Jul 16, 2018 · 7 comments

Comments

@vks
Copy link
Collaborator

vks commented Jul 16, 2018

This syntactic sugar would allow to use Uniform::from(1..=10) instead of Uniform::new_inclusive(1, 10), but requires Rust 1.26. I don't think it is worth it to add a feature or raise the minimum required Rust version, but at some point we might want to implement it.

The implementation itself is trivial:

impl<X: SampleUniform> From<::core::ops::RangeInclusive<X>> for Uniform<X> { 
    fn from(r: ::core::ops::RangeInclusive<X>) -> Uniform<X> {                        
        Uniform::new_inclusive(r.start, r.end)                               
    }                                                                        
}                                                                            
@dhardy
Copy link
Member

dhardy commented Jul 16, 2018

Good idea.

This is at least the third incentive I've come across to require Rust 1.26, although we don't need it.

@vks
Copy link
Collaborator Author

vks commented Jul 16, 2018

This is at least the third incentive I've come across to require Rust 1.26, although we don't need it.

I think we should have a release with all the new features possible without bumping the minimal version. The idea is to make adoption of the new API more likely for crates caring about this.

@pitdicker
Copy link
Contributor

pitdicker commented Jul 20, 2018

We already have the nightly feature flag, maybe it makes sense to implement it under that (for now)?

@vks
Copy link
Collaborator Author

vks commented Jul 20, 2018

That would work, however this does not actually require nightly, just Rust 1.26, so it would be a bit weird. Maybe better than nothing? We could also introduce a stable feature flag, which could be used for SIMD as well.

Unfortunately, we don't have conditional compilation for Rust versions AFAIK.

@sicking
Copy link
Contributor

sicking commented Jul 21, 2018

You still can't access .start and .end other than on nightly.

However as of Rust 1.27 you can use .start() and .end().

@dhardy
Copy link
Member

dhardy commented Jul 23, 2018

We could also introduce a stable feature flag

I would prefer to have a rust_1_26 feature flag which gets deprecated once the minimum is or is greater than this version. But it is probably unnecessary.

@vks
Copy link
Collaborator Author

vks commented Jul 23, 2018

I would prefer to have a rust_1_26 feature flag which gets deprecated once the minimum is or is greater than this version. But it is probably unnecessary.

We could reuse this for SIMD though, which I think would make it worthwhile.

vks added a commit to vks/rand that referenced this issue Jul 23, 2018
vks added a commit to vks/rand that referenced this issue Jul 26, 2018
dhardy pushed a commit that referenced this issue Jul 27, 2018
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

No branches or pull requests

4 participants