Add Output implementation for deserializing JSON #218
Closed
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.
I figured that cradle was probably lonely from not having a PR for a while, so I decided to help.
I'm running a bunch of commands (
ord
andbitcoin-cli
) which return JSON on standard output.This PR adds a
Json
struct, which wraps any type that implements deserialize, and deserializes the command's standard output into an instance of that type. It's kind of unfortunate to have an output type which is specific to JSON, and not something that can be used to deserialize anything, but as far as I know, serde doesn't provide a trait which allows you to abstract over serialization formats, so I think adding a struct for each serialization format is the way.serde
andserde_json
are pretty heavy dependencies, andcradle
currently has no dependencies other thanrustversion
, so it might be wise to put this behind an optional, default-off feature flag.(You will notice that there are no tests, and I can thus hear you clutching your pearls, but I promise to write some if you think this is a good idea!)