[Rust] Flexbuffers dependency cleanup and fixes (#5998)

* Fix doc comment warnings

Can't use doc comment "///" syntax on macros, that generates the following warning:

warning: unused doc comment
   --> src\flexbuffer_type.rs:236:5
    |
236 |     /// returns true if and only if the flexbuffer type is `VectorFloat4`.
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ rustdoc does not generate documentation for macros
    |
    = help: to document an item produced by a macro, the macro must produce the documentation as part of its expansion

So switched to just use ordinary "//" comments on these to be warning free

* Upgrade num_enum 0.4.1 -> 0.5.0

* Remove unused and non-working usage of test crates

* Remove usage of abandoned debug_stub_derive crate

Which brought in old pre-v1 syn and quote crates.

This replaces it with just manual Debug trait implementation instead for the 2 cases
This commit is contained in:
Johan Andersson
2020-06-26 02:12:10 +02:00
committed by GitHub
parent 165a6e3d1e
commit 35d45cac7a
5 changed files with 58 additions and 44 deletions

View File

@@ -14,7 +14,6 @@ categories = ["encoding", "data-structures", "memory-management"]
serde = "1.0" serde = "1.0"
serde_derive = "1.0" serde_derive = "1.0"
byteorder = "1.3.2" byteorder = "1.3.2"
num_enum = "0.4.1" num_enum = "0.5.0"
debug_stub_derive = "0.3.0"
bitflags = "1.2.1" bitflags = "1.2.1"

View File

@@ -181,60 +181,60 @@ impl FlexBufferType {
_ => None, _ => None,
} }
} }
/// returns true if and only if the flexbuffer type is `Null`. // returns true if and only if the flexbuffer type is `Null`.
is_ty!(is_null, Null); is_ty!(is_null, Null);
/// returns true if and only if the flexbuffer type is `Int`. // returns true if and only if the flexbuffer type is `Int`.
is_ty!(is_int, Int); is_ty!(is_int, Int);
/// returns true if and only if the flexbuffer type is `UInt`. // returns true if and only if the flexbuffer type is `UInt`.
is_ty!(is_uint, UInt); is_ty!(is_uint, UInt);
/// returns true if and only if the flexbuffer type is `Float`. // returns true if and only if the flexbuffer type is `Float`.
is_ty!(is_float, Float); is_ty!(is_float, Float);
/// returns true if and only if the flexbuffer type is `Bool`. // returns true if and only if the flexbuffer type is `Bool`.
is_ty!(is_bool, Bool); is_ty!(is_bool, Bool);
/// returns true if and only if the flexbuffer type is `Key`. // returns true if and only if the flexbuffer type is `Key`.
is_ty!(is_key, Key); is_ty!(is_key, Key);
/// returns true if and only if the flexbuffer type is `String`. // returns true if and only if the flexbuffer type is `String`.
is_ty!(is_string, String); is_ty!(is_string, String);
/// returns true if and only if the flexbuffer type is `IndirectInt`. // returns true if and only if the flexbuffer type is `IndirectInt`.
is_ty!(is_indirect_int, IndirectInt); is_ty!(is_indirect_int, IndirectInt);
/// returns true if and only if the flexbuffer type is `IndirectUInt`. // returns true if and only if the flexbuffer type is `IndirectUInt`.
is_ty!(is_indirect_uint, IndirectUInt); is_ty!(is_indirect_uint, IndirectUInt);
/// returns true if and only if the flexbuffer type is `IndirectFloat`. // returns true if and only if the flexbuffer type is `IndirectFloat`.
is_ty!(is_indirect_float, IndirectFloat); is_ty!(is_indirect_float, IndirectFloat);
/// returns true if and only if the flexbuffer type is `Map`. // returns true if and only if the flexbuffer type is `Map`.
is_ty!(is_map, Map); is_ty!(is_map, Map);
/// returns true if and only if the flexbuffer type is `Vector`. // returns true if and only if the flexbuffer type is `Vector`.
is_ty!(is_heterogenous_vector, Vector); is_ty!(is_heterogenous_vector, Vector);
/// returns true if and only if the flexbuffer type is `VectorInt`. // returns true if and only if the flexbuffer type is `VectorInt`.
is_ty!(is_vector_int, VectorInt); is_ty!(is_vector_int, VectorInt);
/// returns true if and only if the flexbuffer type is `VectorUInt`. // returns true if and only if the flexbuffer type is `VectorUInt`.
is_ty!(is_vector_uint, VectorUInt); is_ty!(is_vector_uint, VectorUInt);
/// returns true if and only if the flexbuffer type is `VectorFloat`. // returns true if and only if the flexbuffer type is `VectorFloat`.
is_ty!(is_vector_float, VectorFloat); is_ty!(is_vector_float, VectorFloat);
/// returns true if and only if the flexbuffer type is `VectorKey`. // returns true if and only if the flexbuffer type is `VectorKey`.
is_ty!(is_vector_key, VectorKey); is_ty!(is_vector_key, VectorKey);
/// returns true if and only if the flexbuffer type is `VectorString`. // returns true if and only if the flexbuffer type is `VectorString`.
is_ty!(is_vector_string, VectorString); is_ty!(is_vector_string, VectorString);
/// returns true if and only if the flexbuffer type is `VectorBool`. // returns true if and only if the flexbuffer type is `VectorBool`.
is_ty!(is_vector_bool, VectorBool); is_ty!(is_vector_bool, VectorBool);
/// returns true if and only if the flexbuffer type is `VectorInt2`. // returns true if and only if the flexbuffer type is `VectorInt2`.
is_ty!(is_vector_int2, VectorInt2); is_ty!(is_vector_int2, VectorInt2);
/// returns true if and only if the flexbuffer type is `VectorUInt2`. // returns true if and only if the flexbuffer type is `VectorUInt2`.
is_ty!(is_vector_uint2, VectorUInt2); is_ty!(is_vector_uint2, VectorUInt2);
/// returns true if and only if the flexbuffer type is `VectorFloat2`. // returns true if and only if the flexbuffer type is `VectorFloat2`.
is_ty!(is_vector_float2, VectorFloat2); is_ty!(is_vector_float2, VectorFloat2);
/// returns true if and only if the flexbuffer type is `VectorInt3`. // returns true if and only if the flexbuffer type is `VectorInt3`.
is_ty!(is_vector_int3, VectorInt3); is_ty!(is_vector_int3, VectorInt3);
/// returns true if and only if the flexbuffer type is `VectorUInt3`. // returns true if and only if the flexbuffer type is `VectorUInt3`.
is_ty!(is_vector_uint3, VectorUInt3); is_ty!(is_vector_uint3, VectorUInt3);
/// returns true if and only if the flexbuffer type is `VectorFloat3`. // returns true if and only if the flexbuffer type is `VectorFloat3`.
is_ty!(is_vector_float3, VectorFloat3); is_ty!(is_vector_float3, VectorFloat3);
/// returns true if and only if the flexbuffer type is `VectorInt4`. // returns true if and only if the flexbuffer type is `VectorInt4`.
is_ty!(is_vector_int4, VectorInt4); is_ty!(is_vector_int4, VectorInt4);
/// returns true if and only if the flexbuffer type is `VectorUInt4`. // returns true if and only if the flexbuffer type is `VectorUInt4`.
is_ty!(is_vector_uint4, VectorUInt4); is_ty!(is_vector_uint4, VectorUInt4);
/// returns true if and only if the flexbuffer type is `VectorFloat4`. // returns true if and only if the flexbuffer type is `VectorFloat4`.
is_ty!(is_vector_float4, VectorFloat4); is_ty!(is_vector_float4, VectorFloat4);
/// returns true if and only if the flexbuffer type is `Blob`. // returns true if and only if the flexbuffer type is `Blob`.
is_ty!(is_blob, Blob); is_ty!(is_blob, Blob);
} }

View File

@@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#![cfg_attr(test, feature(test))]
//! Flexbuffers is a high performance schemaless binary data format designed at Google. //! Flexbuffers is a high performance schemaless binary data format designed at Google.
//! It is complementary to the schema-ed format [Flatbuffers](http://docs.rs/flatbuffers/). //! It is complementary to the schema-ed format [Flatbuffers](http://docs.rs/flatbuffers/).
//! See [Flexbuffer Internals](https://google.github.io/flatbuffers/flatbuffers_internals.html) //! See [Flexbuffer Internals](https://google.github.io/flatbuffers/flatbuffers_internals.html)
@@ -35,17 +34,8 @@ extern crate byteorder;
#[macro_use] #[macro_use]
extern crate serde_derive; extern crate serde_derive;
#[macro_use] #[macro_use]
extern crate debug_stub_derive;
extern crate num_enum; extern crate num_enum;
#[cfg(test)]
extern crate quickcheck;
#[cfg(test)]
extern crate quickcheck_derive;
#[cfg(test)]
extern crate rand;
extern crate serde; extern crate serde;
#[cfg(test)]
extern crate test;
mod bitwidth; mod bitwidth;
mod builder; mod builder;

View File

@@ -22,9 +22,8 @@ use std::iter::{DoubleEndedIterator, ExactSizeIterator, FusedIterator, Iterator}
/// MapReaders may be indexed with strings or usizes. `index` returns a result type, /// MapReaders may be indexed with strings or usizes. `index` returns a result type,
/// which may indicate failure due to a missing key or bad data, `idx` returns an Null Reader in /// which may indicate failure due to a missing key or bad data, `idx` returns an Null Reader in
/// cases of error. /// cases of error.
#[derive(DebugStub, Default, Clone)] #[derive(Default, Clone)]
pub struct MapReader<'de> { pub struct MapReader<'de> {
#[debug_stub = "&[..]"]
pub(super) buffer: &'de [u8], pub(super) buffer: &'de [u8],
pub(super) values_address: usize, pub(super) values_address: usize,
pub(super) keys_address: usize, pub(super) keys_address: usize,
@@ -33,6 +32,20 @@ pub struct MapReader<'de> {
pub(super) length: usize, pub(super) length: usize,
} }
// manual implementation of Debug because buffer slice can't be automatically displayed
impl<'de> std::fmt::Debug for MapReader<'de> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
// skips buffer field
f.debug_struct("MapReader")
.field("values_address", &self.values_address)
.field("keys_address", &self.keys_address)
.field("values_width", &self.values_width)
.field("keys_width", &self.keys_width)
.field("length", &self.length)
.finish()
}
}
impl<'de> MapReader<'de> { impl<'de> MapReader<'de> {
/// Returns the number of key/value pairs are in the map. /// Returns the number of key/value pairs are in the map.
pub fn len(&self) -> usize { pub fn len(&self) -> usize {

View File

@@ -143,15 +143,27 @@ macro_rules! as_default {
/// - The `as_T` methods will try their best to return to a value of type `T` /// - The `as_T` methods will try their best to return to a value of type `T`
/// (by casting or even parsing a string if necessary) but ultimately returns `T::default` if it /// (by casting or even parsing a string if necessary) but ultimately returns `T::default` if it
/// fails. This behavior is analogous to that of flexbuffers C++. /// fails. This behavior is analogous to that of flexbuffers C++.
#[derive(DebugStub, Default, Clone)] #[derive(Default, Clone)]
pub struct Reader<'de> { pub struct Reader<'de> {
fxb_type: FlexBufferType, fxb_type: FlexBufferType,
width: BitWidth, width: BitWidth,
address: usize, address: usize,
#[debug_stub = "&[..]"]
buffer: &'de [u8], buffer: &'de [u8],
} }
// manual implementation of Debug because buffer slice can't be automatically displayed
impl<'de> std::fmt::Debug for Reader<'de> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
// skips buffer field
f.debug_struct("Reader")
.field("fxb_type", &self.fxb_type)
.field("width", &self.width)
.field("address", &self.address)
.finish()
}
}
macro_rules! try_cast_fn { macro_rules! try_cast_fn {
($name: ident, $full_width: ident, $Ty: ident) => { ($name: ident, $full_width: ident, $Ty: ident) => {
pub fn $name(&self) -> $Ty { pub fn $name(&self) -> $Ty {