This repository was archived by the owner on Apr 20, 2020. It is now read-only.
fix #55 return the right type on json.num* call#56
Merged
Conversation
ccee7ed to
078db8c
Compare
gavrie
reviewed
Sep 10, 2019
Contributor
There was a problem hiding this comment.
OK, so I tried a bunch of different approaches, and finally settled on this one which isn't too different from the original code. It's the most concise with the least duplication. The most likely contender was based on traits, but it turned out much too verbose.
Please see my latest commits, and let's merge if you're happy with it.
gavrie
previously approved these changes
Sep 11, 2019
gkorland
commented
Sep 11, 2019
src/lib.rs
Outdated
| if let Value::Number(curr_value) = curr_value { | ||
| let in_value = &serde_json::from_str(in_value)?; | ||
| if let Value::Number(in_value) = in_value { | ||
| let (num1, num2) = (curr_value, in_value); |
Contributor
Author
There was a problem hiding this comment.
why do you need this (num1,num2)?
let num_res = match (curr_value.as_i64(), in_value.as_i64()) {
(Some(num1), Some(num2)) => op_i64(num1, num2).into(),
_ => {
let num1 = curr_value.as_f64().unwrap();
let num2 = in_value.as_f64().unwrap();
Number::from_f64(op_f64(num1, num2)).unwrap()
}
};
Seems cleaner not to overload the num1,num2 with two types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.