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

Some way to combine Bounded and Unsigned + Zero #208

Closed
clarfonthey opened this issue Mar 18, 2021 · 3 comments
Closed

Some way to combine Bounded and Unsigned + Zero #208

clarfonthey opened this issue Mar 18, 2021 · 3 comments

Comments

@clarfonthey
Copy link
Contributor

Right now it would be a breaking change to split up the Bounded trait, but I at least have one use case for this after messing around with proptest-rs/proptest#235: there are types that are lower-bounded but not upper-bounded, specifically BigUint. Would be nice to be able to have a trait that lets you get a min_value without requiring a max_value, since right now Bounded and Unsigned + Zero may overlap and we can't rely on that.

@clarfonthey clarfonthey changed the title Some way to combine Bounded and Unsigned Some way to combine Bounded and Unsigned + Zero Mar 18, 2021
@cuviper
Copy link
Member

cuviper commented Mar 18, 2021

I'm surprised there's a scenario where a possibly-negative minimum would be useful without also caring about a maximum. Can you show an example of how you would use this?

Maybe we could have a trait that returns Option<Self> bounds? But I'm not sure if there's any type that would have an upper bound and not lower, so maybe a simple LowerBounded trait is enough.

@clarfonthey
Copy link
Contributor Author

In this particular case, it was because RangeTo can be converted to a Range for unsigned integers and bounded integers, but RangeFull cannot.

bors bot added a commit that referenced this issue Apr 10, 2021
210: Add LowerBounded/UpperBounded traits r=cuviper a=clarfonthey

Potential solution for #208. With a breaking change, these could simply become supertraits of `Bounded`, but until then, we have to deal with blanket implementations.

I added both simply because it was easy to do so, although we could opt to not require both. I don't see it being that negative to include both, however.

Co-authored-by: ltdk <usr@ltdk.xyz>
@clarfonthey
Copy link
Contributor Author

Closing this issue since the PR I merged accounts for this.

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

2 participants