-
Notifications
You must be signed in to change notification settings - Fork 7
Make this crate into a library as well. #2
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
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.
Thanks for you contribution.
I have looked at the changes partially. I'll go through the rest hopefully later today.
* removed a few unwraps in favour of Result inside the lib
src/lib.rs
Outdated
Ok(process::match_json(&value1, &value2)) | ||
} | ||
|
||
pub fn display_output(result: Mismatch) -> Result<(), std::io::Error> { |
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.
display_output
writes to the stdout. This responsibility should not lie with the library.
Do you think it'll be better to refactor the 'writing to stdout' part out of this and into the binary?
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 agree with what you said about display_output being part of the binary. compare_jsons
should be good enough in my opinion. I will move it.
src/lib.rs
Outdated
let value1 = serde_json::from_str(a)?; | ||
let value2 = serde_json::from_str(b)?; |
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.
We're losing the specificity of the error here - this is helpful to point out to user exactly where the error happens. The Message
constants are there to specify the exact errors this crate can run into and report those.
If you think the exact errors returned by the serde_json
are important (or useful), can you see if the Message
can be re-purposed to hold an Error
, but still have a useful message on top?
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.
Agree. From my requirement's perspective, it isn't much of an importance, but as a library, it is a good to have. I will accommodate that.
The requested changes are added. I've added a derive |
Thank you very much @ksceriath |
@ksceriath Would you be uploading this into http://crates.io/, or should we use it as |
I've published v0.1.2 on crates.io |
Hello,
Thank you for this crate. We have a requirement in one of our project where we could use this as a library dependency. I've moved the core functions and the related tests that you've written in your main.rs into a library so that we can use it from the https://crates.io. None of the core functionalities were altered, only a refactor to use this as a library.
Currently, we are using this in our cargo.toml as
It'd be great if you can consider reviewing this PR.
[lib]
and[[bin]]
sections in theCargo.toml
file to keep this a binary, while also supporting to be a librarymain.rs
tolib.rs
and changed scope to pub so that this can be called from other crates.lib.rs
compare_jsons
anddisplay_output
functions to typeResult
and return error in favour ofunwrap()
, and made the changes inmain.rs
while calling these functions.Fixes available as a library? #1
Thanks.