-
Notifications
You must be signed in to change notification settings - Fork 47
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
Rust: Add serde json support #117
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.
Couple of small things, otherwise this looks good. Before we merge this I'd like to experiment with the output in rs-stellar-xdr to see if there are other things we should tweak.
@@ -1,5 +1,8 @@ | |||
use core::{array::TryFromSliceError, fmt, fmt::Debug, ops::Deref}; | |||
|
|||
#[cfg(feature = "serde")] | |||
use serde::{Deserialize, Serialize}; |
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'd be inclined to remove the use
and fully qualify the serde types at their call sites. I don't think it will be too burdensome, and I think it will aid readability since the type names are rather generic and the crate name will help provide context at their use.
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.
Done
lib/xdrgen/generators/rust.rb
Outdated
@@ -134,6 +134,7 @@ def render_source_comment(out, defn) | |||
|
|||
def render_struct(out, struct) | |||
out.puts "#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]" | |||
out.puts "#[cfg_attr(feature = \"serde\", derive(Serialize, Deserialize), serde(rename_all = \"camelCase\"))]" |
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.
It is common in Ruby to use alternative string style when the string will contain double quotes:
out.puts "#[cfg_attr(feature = \"serde\", derive(Serialize, Deserialize), serde(rename_all = \"camelCase\"))]" | |
out.puts %{#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(rename_all = "camelCase"))]} |
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.
Done
Co-authored-by: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com>
Some other things I'd like to explore, but depending on difficulty we can kick them down the road: |
Initial implementation of #112.
Deserialization of
Box
andVecM
is not implemented yet withoutalloc
. Should be fixed as part of stellar/rs-stellar-xdr#47.Close #112