mirror of
https://github.com/google/flatbuffers.git
synced 2026-07-01 00:01:37 +00:00
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:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user