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

@@ -102,11 +102,20 @@ impl flatbuffers::EndianScalar for EnumInNestedNS {
// struct StructInNestedNS, aligned to 4
#[repr(C, align(4))]
#[derive(Clone, Copy, Debug, PartialEq)]
#[derive(Clone, Copy, PartialEq)]
pub struct StructInNestedNS {
a_: i32,
b_: i32,
} // pub struct StructInNestedNS
impl std::fmt::Debug for StructInNestedNS {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.debug_struct("StructInNestedNS")
.field("a", &self.a())
.field("b", &self.b())
.finish()
}
}
impl flatbuffers::SafeSliceAccess for StructInNestedNS {}
impl<'a> flatbuffers::Follow<'a> for StructInNestedNS {
type Inner = &'a StructInNestedNS;
@@ -166,7 +175,7 @@ impl StructInNestedNS {
}
pub enum TableInNestedNSOffset {}
#[derive(Copy, Clone, Debug, PartialEq)]
#[derive(Copy, Clone, PartialEq)]
pub struct TableInNestedNS<'a> {
pub _tab: flatbuffers::Table<'a>,
@@ -243,6 +252,13 @@ impl<'a: 'b, 'b> TableInNestedNSBuilder<'a, 'b> {
}
}
impl std::fmt::Debug for TableInNestedNS<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut ds = f.debug_struct("TableInNestedNS");
ds.field("foo", &self.foo());
ds.finish()
}
}
} // pub mod NamespaceB
} // pub mod NamespaceA