Implement Debug trait for Rust flatbuffers. (#6207)

* Refactor idl_gen_rust to a ForAllX continuation pattern.

* Removed unneeded SetValue and updated sample rust gencode

* Make Rust flatbuffers print right

* Generated code and removed unnecessary trait constraint

* bumped rust version. Release required

* removed an unwrap in Rust Debug-print unions

* Tested formatting flatbuffers in rust.

* Set float precision in flaky debug-print test

* impl Debug for structs too

Co-authored-by: Casper Neo <cneo@google.com>
This commit is contained in:
Casper
2020-10-29 12:57:29 -07:00
committed by GitHub
parent 17ae48decc
commit b08b0a4402
12 changed files with 508 additions and 27 deletions

View File

@@ -21,7 +21,7 @@ pub mod namespace_a {
use self::flatbuffers::EndianScalar;
pub enum TableInFirstNSOffset {}
#[derive(Copy, Clone, Debug, PartialEq)]
#[derive(Copy, Clone, PartialEq)]
pub struct TableInFirstNS<'a> {
pub _tab: flatbuffers::Table<'a>,
@@ -122,8 +122,17 @@ impl<'a: 'b, 'b> TableInFirstNSBuilder<'a, 'b> {
}
}
impl std::fmt::Debug for TableInFirstNS<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut ds = f.debug_struct("TableInFirstNS");
ds.field("foo_table", &self.foo_table());
ds.field("foo_enum", &self.foo_enum());
ds.field("foo_struct", &self.foo_struct());
ds.finish()
}
}
pub enum SecondTableInAOffset {}
#[derive(Copy, Clone, Debug, PartialEq)]
#[derive(Copy, Clone, PartialEq)]
pub struct SecondTableInA<'a> {
pub _tab: flatbuffers::Table<'a>,
@@ -200,6 +209,13 @@ impl<'a: 'b, 'b> SecondTableInABuilder<'a, 'b> {
}
}
impl std::fmt::Debug for SecondTableInA<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut ds = f.debug_struct("SecondTableInA");
ds.field("refer_to_c", &self.refer_to_c());
ds.finish()
}
}
} // pub mod NamespaceA
#[allow(unused_imports, dead_code)]
@@ -213,7 +229,7 @@ pub mod namespace_c {
use self::flatbuffers::EndianScalar;
pub enum TableInCOffset {}
#[derive(Copy, Clone, Debug, PartialEq)]
#[derive(Copy, Clone, PartialEq)]
pub struct TableInC<'a> {
pub _tab: flatbuffers::Table<'a>,
@@ -302,5 +318,13 @@ impl<'a: 'b, 'b> TableInCBuilder<'a, 'b> {
}
}
impl std::fmt::Debug for TableInC<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut ds = f.debug_struct("TableInC");
ds.field("refer_to_a1", &self.refer_to_a1());
ds.field("refer_to_a2", &self.refer_to_a2());
ds.finish()
}
}
} // pub mod NamespaceC