-
Notifications
You must be signed in to change notification settings - Fork 123
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
Integer support #210
Integer support #210
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me, thank you!
src/value.rs
Outdated
/// assert_eq!(i.get(), 5.0); | ||
/// assert_eq!(f.get(), 2.0); | ||
/// ``` | ||
pub fn get(self) -> f64 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be called into_f64
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have a deprecated get
that is an alias for into_f64
for backwards compatibility?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought your PR is API breaking anyway, isn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. sorry, since floats are strictly not equal to integers of the same value. Do you think it's worthwhile to try to preserve this equality at all for compatibility or otherwise?
@torkleyy would you want to review? I figured you know the value semantics better :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! We'll squash on merge.
The rebase is done. Is there anything else needed here from me? |
Sorry, this needs to be rebased again. |
@kvark No problemo. Should be good now. |
@CAD97 looks like GHA isn't configured correctly. It doesn't even run on this PR. |
@elrnv thank you! Unfortunately we can't proceed until we get CI looking at this. |
Thank you! I think the CI fix need to go separately first. |
I thought there was an option to run GHA on forks, but I can't find it anymore. I was just trying to see if this would work... :/ |
@kvark I set it up the same way that Travis was, to only run on pushes to master/staging/trying. We can set it up to run on PRs as well, that's just another entry to the |
@CAD97 travis was definitely checking other forks PRs |
#227 bumps up the CI to always run on any PR or any push. Bors would have (of course) still tested on CI. |
Can we rebase and squash please? |
Extend the number value variant to distinguish between signed integers and floats. Add a doc test for map_to on Number. Added Number::Integer constructors from: - u64 since we get these for positive integers from the parser. - i32 since integers default to i32 in Rust, making the simple integer construction compile: Number::new(3) -> Number::Integer(3)
.... I have no idea why GHA aren't running on this PR now. I can only suggest a |
I'll try to close and re-open it. |
Doesn't seem to help :/ |
Maybe related to: Update - We are continuing to work on a fix for the elevated error rates. |
CI has run now, anyway. |
bors r+ |
Build succeeded: |
Roughly following the discussion from #47 and related issues and PRs, this PR extends the Number type (and so indirectly the Value type) to support integers. I hope I didn't grossly misunderstand the discussion there, but I am keen to make adjustments here to make the project better.
I tried to limit the impact to the API to a single breaking change by extending the already opaqueNumber
type rather than theValue
enum which exposes its structure. The breaking change is that theget
method inNumber
is replaced byas_f64
andas_i64
for getting the appropriate type.Since
Integer
andFloat
types are distinct, they will not be ordered by value (as explained below). This is a breaking change in itself.To maintain the traits on
Number
,Integer
s are simply ordered beforeFloat
s. This makes float and integer not comparable in value (e.g.Number::Integer(2)
<Number::Float(Float(1.0))
) because I didn't see any necessity to do so, but I'm open to suggestions.The tests are adjusted to verify that both integers and floats are working.