Implement Serialize on generated rust types (#7022)

* fix for rust build

* Rust: Implement Serialize on generated types

For debugging convenience it is really handy to be able to dump out
types as another format (ie: json). For example, if we are logging a
type to a structured logging system, or even printing it out in a
structured way to the console.

Right now we handle this by shelling out to `flatc` which is not ideal;
by implementing Serialize on the generated types we can use any of the
Serializer-implementing packages for our structured debug output.

* clang-format

* Make the flatbuffers Rust crate only have an optional dependency on the `serde` packages.

* fix warning

* fix rust test build

* Oh yeah this needs to be initialized

* fix toml syntax

* code review feedback

* rebuild test data
This commit is contained in:
Max Burke
2022-01-30 16:29:18 -08:00
committed by GitHub
parent dd8fccfb1b
commit 1d294a31b8
67 changed files with 5455 additions and 1 deletions

View File

@@ -626,6 +626,9 @@ struct IDLOptions {
// If set, require all fields in a table to be explicitly numbered.
bool require_explicit_ids;
// If set, implement serde::Serialize for generated Rust types
bool rust_serialize;
// The corresponding language bit will be set if a language is included
// for code generation.
unsigned long lang_to_generate;
@@ -690,6 +693,7 @@ struct IDLOptions {
json_nested_legacy_flatbuffers(false),
mini_reflect(IDLOptions::kNone),
require_explicit_ids(false),
rust_serialize(false),
lang_to_generate(0),
set_empty_strings_to_null(true),
set_empty_vectors_to_null(true) {}