Skip to content
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

Merged
merged 6 commits into from
Jul 13, 2022
Merged

Rust: Add serde json support #117

merged 6 commits into from
Jul 13, 2022

Conversation

sisuresh
Copy link
Contributor

@sisuresh sisuresh commented Jul 12, 2022

Initial implementation of #112.

Deserialization of Box and VecM is not implemented yet without alloc. Should be fixed as part of stellar/rs-stellar-xdr#47.

Close #112

@sisuresh sisuresh marked this pull request as draft July 12, 2022 21:27
@leighmcculloch leighmcculloch changed the title Add serde support Rust: Add serde json support Jul 12, 2022
@sisuresh sisuresh marked this pull request as ready for review July 13, 2022 00:04
Copy link
Member

@leighmcculloch leighmcculloch left a 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.

lib/xdrgen/generators/rust.rb Outdated Show resolved Hide resolved
@@ -1,5 +1,8 @@
use core::{array::TryFromSliceError, fmt, fmt::Debug, ops::Deref};

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
Copy link
Member

@leighmcculloch leighmcculloch Jul 13, 2022

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -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\"))]"
Copy link
Member

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:

Suggested change
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"))]}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

sisuresh and others added 2 commits July 12, 2022 17:13
Co-authored-by: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com>
@leighmcculloch
Copy link
Member

leighmcculloch commented Jul 13, 2022

Some other things I'd like to explore, but depending on difficulty we can kick them down the road:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rust: Add JSON ser/der to all generated types
2 participants