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

Optional Scalars support for Rust #6034

Merged
merged 6 commits into from
Jul 23, 2020
Merged

Optional Scalars support for Rust #6034

merged 6 commits into from
Jul 23, 2020

Conversation

CasperN
Copy link
Collaborator

@CasperN CasperN commented Jul 19, 2020

Context on Optional Scalars: #6014. This CL enables optional scalars in Rust. The schema

table Monster { mana: int = null; }

generates code like

impl Monster {
  fn mana() -> Option<i32>;
}

and analogously for other scalars. See tests/optional_scalars_generated.rs for a detailed example. In addition to modifying idl_gen_rust.cc to support optional scalars, I also cleaned up the code a bit:

  • I removed the special casing offtBool and ftVectorBool. This lead to a minor whitespace change in the generated code, I left a TODO to fix that in a future CL.
  • I deleted the GetDefaultConstant function that seems to do nothing.
  • Removed an unused #[macro_use] in Flexbuffers.

Props to @rw for writing the Rust Flabuffers library in such a way that no changes were needed for this feature.

@aardappel
Copy link
Collaborator

Generally looks good to me, and a good template (and schema) to follow for other languages.

@rw can comment on Rust specifics :)

@CasperN
Copy link
Collaborator Author

CasperN commented Jul 22, 2020

Bump @rw

@rw rw merged commit 043b52b into google:master Jul 23, 2020
@rw
Copy link
Collaborator

rw commented Jul 23, 2020

@CasperN LGTM! Thanks for cleaning up some of the conditionals in the generator, too.

ivannp pushed a commit to ivannp/flatbuffers that referenced this pull request Oct 2, 2020
* First draft of rust optionals

* Code cleanup around ftBool and ftVectorOfBool

* Tests for Rust optional scalars

* test bools too

Co-authored-by: Casper Neo <cneo@google.com>
@CasperN CasperN deleted the ruopt branch August 24, 2021 13:49
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.

3 participants