Rust Object API (#6070)

* inital commit of rust object api

* Required fields support.

* clang fallthrough

* Fix unused variables

* just don't fall through

* remove comment

* s/panic/unreachable

* Tests for object API

* Added defaults

* deleted unintentionally added files and updated .bat file

* fix bat file

* clang format

* Cargo clippy checks

* remove commented out code

* clippy allows

* Remove matches! macro since we're not yet at Rust v1.42

* install clippy in RustTest.sh

* move line

Co-authored-by: Casper Neo <cneo@google.com>
This commit is contained in:
Casper
2021-01-22 13:07:32 -05:00
committed by GitHub
parent 796ed68faf
commit 1da0a2dfac
21 changed files with 2362 additions and 319 deletions

View File

@@ -242,9 +242,7 @@ impl<'a> Builder {
let address = self.buffer.len();
for &b in xs.iter() {
self.buffer.push(b as u8);
for _ in 0..width as u8 {
self.buffer.push(0); // Well this seems wasteful.
}
self.buffer.resize(self.buffer.len() + width as usize, 0);
}
self.values.push(Value::Reference {
fxb_type: FlexBufferType::VectorBool,

View File

@@ -129,9 +129,10 @@ impl Value {
!self.is_inline()
}
pub fn is_key(&self) -> bool {
match self {
Value::Key(_) => true,
_ => false,
if let Value::Key(_) = self {
true
} else {
false
}
}
pub fn is_typed_vector_or_map(&self) -> bool {

View File

@@ -134,7 +134,7 @@ impl FlexBufferType {
/// Returns true if called on a map, vector, typed vector, or fixed length typed vector.
pub fn is_vector(self) -> bool {
let d = self as u8;
9 <= d && d < 25 || self == VectorBool
(9..25).contains(&d) || self == VectorBool
}
/// True iff the binary format stores the length.
/// This applies to Blob, String, Maps, and Vectors of variable length.

View File

@@ -28,6 +28,10 @@
// Serializable structs are Pushable
// Serde with maps - field names and type names.
// Until flat/flexbuffers is on Rust v1.42, we cannot use the previously unstable matches! macro.
#![allow(clippy::unknown_clippy_lints)]
#![allow(clippy::match_like_matches_macro)]
#[macro_use]
extern crate bitflags;
extern crate byteorder;