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

@@ -19,6 +19,7 @@ use std::marker::PhantomData;
use std::mem::size_of;
use std::slice::from_raw_parts;
use std::str::from_utf8_unchecked;
use std::fmt::{Debug, Result, Formatter};
use crate::endian_scalar::read_scalar_at;
#[cfg(target_endian = "little")]
@@ -26,9 +27,19 @@ use crate::endian_scalar::EndianScalar;
use crate::follow::Follow;
use crate::primitives::*;
#[derive(Debug)]
pub struct Vector<'a, T: 'a>(&'a [u8], usize, PhantomData<T>);
impl<'a, T> Debug for Vector<'a, T>
where
T: 'a + Follow<'a>,
<T as Follow<'a>>::Inner : Debug
{
fn fmt(&self, f: &mut Formatter) -> Result {
f.debug_list().entries(self.iter()).finish()
}
}
// We cannot use derive for these two impls, as it would only implement Copy
// and Clone for `T: Copy` and `T: Clone` respectively. However `Vector<'a, T>`
// can always be copied, no matter that `T` you have.