summaryrefslogtreecommitdiff
path: root/tests/rust_usage_test
AgeCommit message (Collapse)AuthorFilesLines
2021-04-26Rust Remove SafeSliceAccess for Arrays, and fix miri. (#6592)Casper2-8/+4
* Fix Miri flag passing and bump Rust version. * Fix Miri problems from Arrays PR. SafeSliceAccess was removed for Arrays. It's kind of unsound. It has two properties: 1. EndianSafe 2. Alignment 1 We only need 1. in create_vector_direct to memcpy data. We both 1. and 2. for accessing things with slices as buffers are built on &[u8] which is unaligned. Conditional compilation implements SafeSliceAccess for >1byte scalars (like f32) on LittleEndian machines which is wrong since they don't satisfy 2. This UB is still accessible for Vectors (though not exercised our tests) as it implements SafeSliceAccess. I'll fix this later by splitting SafeSliceAccess into its 2 properties. Co-authored-by: Casper Neo <cneo@google.com>
2021-04-26Mark endian_scalar as unsafe. (#6588)Casper2-3/+6
* Mark endian_scalar as unsafe. Also - removed the deprecated flexbuffer slice from example - fixed some cargo warnings * Assertions and read_scalar made unsafe * Clippy lints * Add to Safety Co-authored-by: Casper Neo <cneo@google.com>
2021-04-16[Rust] Add support for fixed size arrays (#6548)Eddie Linder3-5/+339
* Add support for fixed size arrays * clang-format * Update rust image to 1.51 to support const generics * Handle correctly big endian * Add fuzz tests and clean code * Add struct fuzz test and optimize struct arrays for api * Bump flatbuffers crate version
2021-04-06Default-empty vectors of enums (#6505)Casper1-0/+4
* disable clippy * Vector of enum default * swift and tests * git clang format * Rewrite enum parser checks * Remove Voids from more_defaults * vector enum swift * remove vector accessor from swift * clang format Co-authored-by: Casper Neo <cneo@google.com>
2021-03-29Rust structz (#6539)Casper1-0/+33
* Rust structz * struct of structs test * swift tmp variables Co-authored-by: Casper Neo <cneo@google.com>
2021-02-24[rust] Remove debug code (#6475)Colin1-0/+4
* 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-16[rust] Genericize flexbuffer reader (#6450)Colin5-33/+50
* feature/rust-tokio-bytes added feature name for tokio-bytes * Added flexbuffer implementation, TODO: typecast to avoid recurse * Converted codebase to utilize FlexBuffer implementation, need to resolve deserialization issues * Added todo for lifetime issue, may use &'de [u8] for deserializer instead of current method * Added proper &[u8] implementation * Removed unused struct * Added experimental fix to get_slice * Added experimental fix to get_slice * Avoided lifetime issues via ref structs, need to check if this hurts peformance * Updated deserializer implementation to allow for borrowed data from Reader struct * Fixed bug with str * Removed unnecessary generic parameter * Added unsafe to avoid lifetime complaints, current tests pass, need to review alternatives to unsafe * Opinionated: Removed bytes crate as this implementation could be done in a separate crate * Cleaned up flatbuffer * Fixed sample / example * Resolved PR feedback, need to resolve issues with tests * Cleaned up FlexBuffer trait to be an auto impl * Removed TODO * Reverted Deserializer to only support &'de [u8] * Cleaned up / renamed function for clarification * Renamed FlexBuffer -> InternalBuffer for clarification on it's purpose * Fixed issue with key bytes * resolved issues with broken tests, confirming this is a breaking change * Removed FIXME that's solved by splitting String and Key variants * Implemented associated types approach * Fixed backward slice logic * Fixed MapReader compile error * Added from_buffer for deserialization, removed function since it's only needed for deserialization * Removed dead code * Cleaned up buffer, removed AsRef in favor of Deref * Renamed Buffer::as_str -> Buffer::buffer_str * Minor cleanup * Updated documentation, need to fix tests * Removed unnecessary & * Removed unused lifetime * removed unnecessary as_ref * Minor optimization wrap-up * resolved issue with Clone * Added test to verify no deep-copy * Added for optimization * Updated to use empty fn instead of default * Updated comments / test name - plus the 0.3.0 version bump * comment
2021-02-12Default strings and vectors: Parser + Rust support (#6421)Casper2-0/+27
* Fix tests.cpp * Parser support for vector/string defaults * tests and default empty vectors * addressed comments * Default strings and vectors for Rust * Tested Rust more_defaults * git-clang-format * add more_defaults_test * fixed vector default * removed commented out code * more unreachable Co-authored-by: Casper Neo <cneo@google.com>
2021-02-07Implement Rust object API defaults (#6444)Casper2-0/+120
* Implment Rust object API defaults * satisfy return analysis * git clang format Co-authored-by: Casper Neo <cneo@google.com>
2021-01-26Rust: remove inner attributes (#6410)Casper5-1/+92
* remove inner attributes * Added test for outdir in Rust * add bin/outdir * Moved outdir test to its own package and only run it if flatc is available Co-authored-by: Casper Neo <cneo@google.com>
2021-01-25[Rust] Ensure unions are referenced with the correct path (#6422)William Bain1-0/+6
* Add codegen test for namespaced unions * [Rust] Handle cross-namespace union use * [Rust] Test namespace handling * [Rust] Drop trailing whitespace in codegen * [Rust] Set flags in generate_code.bat to match .sh * [C#] Add additional namespace test file
2021-01-22Rust Object API (#6070)Casper4-2/+56
* 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-11Fix Rust UB problems (#6393)Casper7-34/+40
* 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-07[C++, JSON] Fix nullptr access when reading a key with a default value. (#6375)Vladimir Glavnyy1-3/+3
This commit fixes handling of default and NULL `key` fields in `Parser::ParseVector` (#5928). The JSON generator updated. It outputs `key` fields even if the `--force-defaults` option is inactive. Additional test cases for `key` added.
2021-01-04[Rust] Shared String (#6367)mustiikhalil1-0/+47
* Adds shared strings and tests for shared strings * Adds resets on string_map * Moved shared strings to use vector instead of hashmap * Addresses all the issues * Resolves some comments
2020-12-07Rust Flatbuffers Verifier (#6269)Casper4-20/+120
* 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-11-05Added required-nested-flatbuffer to monster_test and fixed rust (#6236)Casper1-2/+4
Co-authored-by: Casper Neo <cneo@google.com>
2020-10-29Implement `Debug` trait for Rust flatbuffers. (#6207)Casper1-0/+50
* 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>
2020-10-22Kotlin test optional enum (#6201)Paulo Pinheiro2-2/+2
* Add test for optional enums in Kotlin * Rename optional_scalars2.fbs into optional_scalars.fbs Also updated all references in the project to point to "optional_scalars.fbs" instead of "optional_scalars2.fbs".
2020-10-19Rework enums in rust. (#6098)Casper2-70/+29
* Rework enums in rust. They're now a unit struct, rather than an enum. This is a backwards incompatible change but the previous version had UB and was also backwards incompatible so... * Update and test sample rust flatbuffers * Use bitflags crate to properly support rust enums. Previously, the bitflags attribute was just ignored. This is a breaking change as the bitflgs API is not like a normal rust enum (duh). * variant_name() -> Option<_> * repr transparent * Reexport bitflags from flatbuffers * Make bitflags constants CamelCase, matching normal enums * Deprecate c-style associated enum constants Co-authored-by: Casper Neo <cneo@google.com>
2020-10-02Ruopt enum (#6156)Casper2-12/+47
* Rust support for optional enums * make optional_scalars2 for languages that support optional enums Co-authored-by: Casper Neo <cneo@google.com>
2020-07-23Optional Scalars support for Rust (#6034)Casper3-1/+60
* First draft of rust optionals * Code cleanup around ftBool and ftVectorOfBool * Tests for Rust optional scalars * test bools too Co-authored-by: Casper Neo <cneo@google.com>
2020-06-28Serde with bytes maps to Blob (#6009)Casper3-3/+12
* Serde with_bytes maps to Blob * Bump rust flexbuffers minor version number Co-authored-by: Casper Neo <cneo@google.com>
2020-06-18Rust Flexbuffers Documentation update (#5979)Casper1-2/+10
* Update samples and docs * Fixed a line of documentation Co-authored-by: Casper Neo <cneo@google.com>
2020-06-08[rust] Add FlatBufferBuilder::force_defaults API (#5946)Matt Brubeck1-0/+19
* [rust] Add force_defaults method FlatBufferBuilder This works just like the same method already available in other languages. * Add binary format test for force_defaults
2020-05-07Rust Flexbuffers (#5669)Casper14-51/+2045
* 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-03-08[Rust] Add gen-name-strings for Rust (#5757)Lee Mracek1-0/+12
* Add gen-name-strings for Rust * Clang format * Add tests and generate with gen-name-strings * Clang-format * Stop doing gen-name-strings with C++ code * Bring generate_code.bat up with generate_code.sh
2020-01-19[rust] Add use declarations to Rust-generated bindings for imported FB ↵Max Burke4-0/+33
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 d554d79fecf5afd6da6fb993b30b4cd523a5889a. * 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-02Rust: Temporarily disable 2 endianness unit tests (#5695)Robert Winslow1-4/+6
Rare failures occur on AppVeyor in these functions; the failures appear spurious.
2019-12-31[rust] Make enum names public (#5690)Max Burke1-0/+34
* 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 d554d79fecf5afd6da6fb993b30b4cd523a5889a. * Address comments raised in PR * Update documentation comments per feedback * Fix typo * [rust] Make enum variant names public. * Update generated test files * Add test for public enum names
2019-12-17Make Rust constants public (#5659)Matt Brubeck1-0/+47
* Make Rust constants public Otherwise they cannot be accessed by code that consumes the generated bindings. * Re-generate test code * Add a test for enum constants
2019-10-28Rust: Add idiomatic iterator for Vector type (#5579)Mathias Svensson1-0/+75
* Rust: Add idiomatic iterator for Vector type * Add comments explaining some implementation details
2019-10-28Rust: Fix Copy and Clone impls for a few generic types (#5577)Mathias Svensson2-0/+16
* Rust: Fix Copy and Clone impls for a few generic types * Add tests for Copy+Clone * Wrap Copy+Clone checks in a #[test] function
2019-09-09Rust: Fixed cargo clippy on non-generated code (#5485)Casper1-6/+9
* Cargo clippy lints * more lints * more lints * Restored a doc comment * Comment on float eps-eq and adjusted casting
2019-03-09[Rust] Don't use inner attributes for `allow` (#5212)bspeice4-0/+4
* 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-08Fix rust crate for big-endian targets (#5229)tymcauley1-64/+84
Thanks for tackling this, @tymcauley ! * big endian docker test -- wip * tweaks * tweaks * tweaks * docker tweaks * fix conditional compilation issues * reactivate other docker tests * try some more cross-platform config (from tymcauley) * Update tests/docker/languages/Dockerfile.testing.rust.big_endian.1_30_1 Co-Authored-By: rw <rw@users.noreply.github.com> * Update tests/docker/languages/Dockerfile.testing.rust.big_endian.1_30_1 Co-Authored-By: rw <rw@users.noreply.github.com> * Update tests/docker/languages/Dockerfile.testing.rust.big_endian.1_30_1 Co-Authored-By: rw <rw@users.noreply.github.com> * Resolved Rust warnings during big-endian builds. * Unify Rust test suites for x86 and MIPS builds. Note that I had to add four extra packages to the MIPS `Dockerfile`: `libexpat1`, `libmagic1`, `libmpdec2`, and `libreadline7`. For a reason I couldn't identify, even the simplest Rust MIPS binaries run with `qemu-mips` would fail with a segfault when run through this `Dockerfile`. After installing the `gdb-multiarch` package to attempt to debug the issue, the binaries ran successfully. I pared down the packages installed by `gdb-multiarch`, and these four packages are the minimum subset necessary to get Rust MIPS binaries running under `qemu-mips`. * Changed Rust tests to use `Vector`s instead of direct-slice-access. The direct-slice-access method is not available on big-endian targets, but `flatbuffers::Vector`s provide an array interface that is available on all platforms. * Resolved FooStruct endianness issues using explicit struct constructor. This more closely resembles how FlatBuffers structs are constructed in generated Rust code. * Added explanation of how `FooStruct` parallels generated struct code. Also collected duplicate implementations of `FooStruct` into a common location.
2019-02-07Reduced `force_align` in tests to 8, to work with --object-api.Wouter van Oortmerssen1-2/+2
More detail: https://github.com/google/flatbuffers/projects/6#card-17401359 See also the .md changes in this commit. Change-Id: Idfa68b2fd3bdb19979833737d3a3cf83ec1d6775
2018-11-29CI: Dockerized language port tests (#5066)Robert1-7/+17
This runs a script in TravisCI that executes a bunch of small Docker image scripts to test the language ports in isolated environments. This allows us to test multiple language versions with little additional complexity. Covers: + Java OpenJDK 10.0.2 + Java OpenJDK 11.0.1 + Node 10.13.0 + Node 11.2.0 + Python CPython 2.7.15 + Python CPython 3.7.1 + Rust 1.30.1
2018-11-29Fix create_vector_of_strings to use the stack, and test it. (#5074)Robert1-1/+3
2018-11-16disable unimportant RAM-heavy test b/c Windows (#5047)Robert1-4/+5
2018-10-31Rust: test that no heap allocs happen on hot paths (#5022)Robert2-0/+144
2018-09-28Remove lifetime specifier on table getter methods (#4949)Matt Mastracci1-0/+17
With the old-style code, the test fails with a borrow-checker error: ``` #[inline] pub fn name(&'a self) -> &'a str { self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(Monster::VT_NAME, None).unwrap() } ``` ``` error[E0597]: `e` does not live long enough --> tests/integration_test.rs:273:57 | 273 | let enemy_of_my_enemy = monster.enemy().map(|e| e.name()); | ^ - `e` dropped here while still borrowed | | | borrowed value does not live long enough 274 | assert_eq!(enemy_of_my_enemy, Some("Fred")); 275 | } | - borrowed value needs to live until here ```
2018-09-27loosen lifetimes in type signature of Table::get (#4925)kzvi1-0/+31
2018-09-26don't return Option from required table field accessors (#4926)kzvi1-23/+20
2018-09-26rust: Fixed MakeCamelCase (#4932) (#4936)jean-airoldie1-1/+1
* Fixed MakeCamelCase behavior when supplied Upper_Camel_Case, snake_case and UPPERCASE strings. * Modified the rust integration test to reflect changes.
2018-09-03delete and ignore Cargo.lock files (#4906)Robert1-285/+0
2018-09-02Port FlatBuffers to Rust (#4898)Robert5-0/+3182
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.