summaryrefslogtreecommitdiff
path: root/rust
diff options
context:
space:
mode:
authorCasper <casperneo@uchicago.edu>2020-10-29 12:57:29 -0700
committerGitHub <noreply@github.com>2020-10-29 12:57:29 -0700
commitb08b0a440226540a5157bb7ec1e82644ef228004 (patch)
treeca418f1fea9dcc00731207e4767242abe8e07589 /rust
parent17ae48decc9101beaa850e1208ea067ed0da26c3 (diff)
downloadflatbuffers-b08b0a440226540a5157bb7ec1e82644ef228004.tar.gz
flatbuffers-b08b0a440226540a5157bb7ec1e82644ef228004.tar.bz2
flatbuffers-b08b0a440226540a5157bb7ec1e82644ef228004.zip
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>
Diffstat (limited to 'rust')
-rw-r--r--rust/flatbuffers/src/vector.rs13
1 files changed, 12 insertions, 1 deletions
diff --git a/rust/flatbuffers/src/vector.rs b/rust/flatbuffers/src/vector.rs
index 3079649d..5236ea16 100644
--- a/rust/flatbuffers/src/vector.rs
+++ b/rust/flatbuffers/src/vector.rs
@@ -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.