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

@@ -1532,6 +1532,56 @@ mod write_and_read_examples {
serialized_example_is_accessible_and_correct(&buf[..], true, false).unwrap();
}
#[test]
fn generated_code_debug_prints_correctly() {
let b = &mut flatbuffers::FlatBufferBuilder::new();
create_serialized_example_with_generated_code(b);
let buf = b.finished_data();
serialized_example_is_accessible_and_correct(&buf, true, false).unwrap();
let m = super::my_game::example::get_root_as_monster(buf);
assert_eq!(
format!("{:.5?}", &m),
"Monster { pos: Some(Vec3 { x: 1.00000, y: 2.00000, z: 3.00000, \
test1: 3.00000, test2: Green, test3: Test { a: 5, b: 6 } }), \
mana: 150, hp: 80, name: \"MyMonster\", \
inventory: Some([0, 1, 2, 3, 4]), color: Blue, test_type: Monster, \
test: Monster { pos: None, mana: 150, hp: 100, name: \"Fred\", \
inventory: None, color: Blue, test_type: NONE, test: None, \
test4: None, testarrayofstring: None, testarrayoftables: None, \
enemy: None, testnestedflatbuffer: None, testempty: None, \
testbool: false, testhashs32_fnv1: 0, testhashu32_fnv1: 0, \
testhashs64_fnv1: 0, testhashu64_fnv1: 0, testhashs32_fnv1a: 0, \
testhashu32_fnv1a: 0, testhashs64_fnv1a: 0, testhashu64_fnv1a: 0, \
testarrayofbools: None, testf: 3.14159, testf2: 3.00000, testf3: 0.00000, \
testarrayofstring2: None, testarrayofsortedstruct: None, flex: None, \
test5: None, vector_of_longs: None, vector_of_doubles: None, \
parent_namespace_test: None, vector_of_referrables: None, \
single_weak_reference: 0, vector_of_weak_references: None, \
vector_of_strong_referrables: None, co_owning_reference: 0, \
vector_of_co_owning_references: None, non_owning_reference: 0, \
vector_of_non_owning_references: None, any_unique_type: NONE, \
any_unique: None, any_ambiguous_type: NONE, any_ambiguous: None, \
vector_of_enums: None, signed_enum: None }, test4: Some([Test { \
a: 10, b: 20 }, Test { a: 30, b: 40 }]), \
testarrayofstring: Some([\"test1\", \"test2\"]), \
testarrayoftables: None, enemy: None, testnestedflatbuffer: None, \
testempty: None, testbool: false, testhashs32_fnv1: 0, \
testhashu32_fnv1: 0, testhashs64_fnv1: 0, testhashu64_fnv1: 0, \
testhashs32_fnv1a: 0, testhashu32_fnv1a: 0, testhashs64_fnv1a: 0, \
testhashu64_fnv1a: 0, testarrayofbools: None, testf: 3.14159, \
testf2: 3.00000, testf3: 0.00000, testarrayofstring2: None, \
testarrayofsortedstruct: None, flex: None, test5: None, \
vector_of_longs: None, vector_of_doubles: None, \
parent_namespace_test: None, vector_of_referrables: None, \
single_weak_reference: 0, vector_of_weak_references: None, \
vector_of_strong_referrables: None, co_owning_reference: 0, \
vector_of_co_owning_references: None, non_owning_reference: 0, \
vector_of_non_owning_references: None, any_unique_type: NONE, \
any_unique: None, any_ambiguous_type: NONE, any_ambiguous: None, \
vector_of_enums: None, signed_enum: None }"
);
}
#[test]
fn generated_code_creates_correct_example_repeatedly_with_reset() {
let b = &mut flatbuffers::FlatBufferBuilder::new();