Commit Graph

11 Commits

Author SHA1 Message Date
Colin c0be1cb7a5
[rust] Remove debug code (#6475)
* Remove debug code

This was added for testing in the recent genericize PR for flexbuffer Reader.

* Added alloc tests -> MapReader::{is_empty, index_key, len}

* Added , accessible through Deref to deprecation warning
2021-02-24 13:00:18 -05:00
Casper 1da0a2dfac
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>
2021-01-22 13:07:32 -05:00
Casper 408cf58024
Fix Rust UB problems (#6393)
* Fix miri problems by assuming alignment is 1 in rust

* Removed is_aligned fn from rust verifier.

* Add back is_aligned, but make it w.r.t. buffer[0]

* touch unused variable

* touch unused variable

* +nightly

* Move Rust miri testing into its own docker

* fix bash

* missing one endian conversion

* fix endianness2

* format stuff

Co-authored-by: Casper Neo <cneo@google.com>
2021-01-11 15:24:52 -05:00
Casper 442949bc11
Rust Flatbuffers Verifier (#6269)
* Updated comments and fixed a fundemental type error.

* bump rust flatbuffers semver

* Initial commit with verifier, need to clean up

* Verifier tested. Needs clean up and refactoring.

* Display for InvalidFlatbuffer and better errors for strings

* SimpleToVerify, some refactoring

* Combined VerifierType TableAccessorFuncBody into FollowType

* scrub todos

* Update Rust get_root functions.

There are 6 variants, with verifier options, default verifier options
and no verification "fast".

* Rename root fns

* inline

* Update to use thiserror

* fix for bad compiler

* improve error formatting

* Replace multiply with saturating_multiply

* saturating adds too

* Add docs disclaiming experimental verification system

Co-authored-by: Casper Neo <cneo@google.com>
2020-12-07 18:37:51 -05:00
Casper 8be05f6bd4
Rust Flexbuffers (#5669)
* Cargo clippy lints

* more lints

* more lints

* Restored a doc comment

* Comment on float eps-eq and adjusted casting

* Rust Flexbuffers

* more serde tests, removed some unsafe

* Redid serde to be map-like and Reader is Display

* Moved iter from Reader to VectorReader

* Serious quickcheck + bugs

* wvo api

* Made types smaller for a reasonable speedup

* redid reading in a way that's a bit faster.

Profiling shows the rust slowdown as building +10%, reading +20%

* src/bin are developer binaries in rust

* Root and Map width are not packed

* key null check is debug only + doc changes

* BuilderOptions

* Documentation

* Documentation

* Moved tests to rust_usage_test

* Moved rust flexbuffers samples to Flatbuffers/samples

* Fixed RustTest

* Fixed for Rust 1.37.0

* Upgraded to rust 1_40_0

* fixed a little-endian-only feature in a test

* 1.40.0

* fixed some benchmarks for bigendian

* Updated .bat file

* misspelling

* Gold Flexbuffer test.

* Serialize,Deserialize, std::error::Error for Errors.

* Undo rustfmt in integration_test.rs

* from_slice instead of from_vec

* Added comments to unsafe blocks

* expanded on comment

* bump

Co-authored-by: CasperN <cneo@google.com>
2020-05-07 14:11:26 -07:00
Max Burke 6da1cf79d9 [rust] Add use declarations to Rust-generated bindings for imported FB definitions (#5645)
* Bugfix for Rust generation of union fields named with language keywords

Looking at ParseField, it appears that in the case of unions, an extra field with a `UnionTypeFieldSuffix` is added to the type definition, however, if the name of this field is a keyword in the target language, it isn't escaped.

For example, if generating code for rust for a union field named `type`, flatc will generate a (non-keyword escaped) field named `type_type` for this hidden union field, and one (keyword escaped) called `type_` for the actual union contents.

When the union accessors are generated, they refer to this `type_type` field, but they will escape it mistakenly, generating code like this:

```
  #[inline]
  #[allow(non_snake_case)]
  pub fn type__as_int(&self) -> Option<Int<'a>> {
    if self.type__type() == Type::Int {
      self.type_().map(|u| Int::init_from_table(u))
    } else {
      None
    }
  }
```

Which will fail to build because the field is called `self.type_type()`, not `self.type__type()`.

* [Rust] Add crate-relative use statements for FBS includes.

At present if a flatbuffer description includes a reference to a type in
another file, the generated Rust code needs to be hand-modified to add
the appropriate `use` statements.

This assumes that the dependencies are built into the same crate, which
I think is a reasonable assumption?

* Revert "[Rust] Add crate-relative use statements for FBS includes."

This reverts commit d554d79fec.

* Add updated generated test files.

* Fixing Rust test harness to handle new includes.

Test binaries need to add references to generated code that's
transitively included.

This also has the knock-on in that this code (which is referenced by
include directives directly in the flatbuffer schema files) also needs
to be generated, hence the changes to generate_code.sh.

* Test harnesses expect test data to be checked in.

Put include_test2 files into the same directory as the include_test2
schema definition.

Update all code generation scripts (forgot the batch file from last
time).

Path updates in Rust test.

* Include updated generated code

* Address comments raised in PR

* Fix failing Rust tests.

* Previous merge clobbered this branch change.

* Add updated imports to benchmarks.

* Clarifying comment per PR request

* Update documentation comments per feedback

* Remove non-Rust generated files for include tests, per feedback from @rw/@aardappel

* Broken code generation batch file

* Fix typo

* Add TODO for tidying up use declaration traversal sometime in the future

* Update test files.
2020-01-19 14:47:28 -08:00
Casper c0282873fb Rust: Fixed cargo clippy on non-generated code (#5485)
* Cargo clippy lints

* more lints

* more lints

* Restored a doc comment

* Comment on float eps-eq and adjusted casting
2019-09-09 13:02:43 -07:00
bspeice 3968d00568 [Rust] Don't use inner attributes for `allow` (#5212)
* Don't use inner attributes for `allow`
Messes with being able to easily include elsewhere

* Regenerate tests

* No-op to retrigger CI

* Add the rest of the `allow` attributes
2019-03-09 12:58:27 -08:00
Robert b378b8eb69
Fix create_vector_of_strings to use the stack, and test it. (#5074) 2018-11-29 11:47:28 -08:00
Robert 4c3b6c247d
Rust: test that no heap allocs happen on hot paths (#5022) 2018-10-31 18:08:14 -07:00
Robert 3c54fd964b Port FlatBuffers to Rust (#4898)
This is a port of FlatBuffers to Rust. It provides code generation and a
runtime library derived from the C++ implementation. It utilizes the
Rust type system to provide safe and fast traversal of FlatBuffers data.

There are 188 tests, including many fuzz tests of roundtrips for various
serialization scenarios. Initial benchmarks indicate that the canonical
example payload can be written in ~700ns, and traversed in ~100ns.

Rustaceans may be interested in the Follow, Push, and SafeSliceAccess
traits. These traits lift traversals, reads, writes, and slice accesses
into the type system, providing abstraction with no runtime penalty.
2018-09-02 18:26:55 -07:00