New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port FlatBuffers to Rust #4898

Merged
merged 37 commits into from Sep 3, 2018

Conversation

Projects
None yet
8 participants
@rw
Collaborator

rw commented Aug 29, 2018

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.

@ry

This comment has been minimized.

Show comment
Hide comment
@ry

ry Aug 29, 2018

Awesome work @rw - thank you! We're already using your patch in our project and it's working great.

ry commented Aug 29, 2018

Awesome work @rw - thank you! We're already using your patch in our project and it's working great.

@aardappel aardappel self-requested a review Aug 29, 2018

@rw rw self-assigned this Aug 29, 2018

@phayes

This comment has been minimized.

Show comment
Hide comment
@phayes

phayes Aug 30, 2018

Should the fie tests/rust_usage_test/test_bench_output.txt have been included in this PR?

phayes commented Aug 30, 2018

Should the fie tests/rust_usage_test/test_bench_output.txt have been included in this PR?

@rw

This comment has been minimized.

Show comment
Hide comment
@rw

rw Aug 30, 2018

Collaborator

@phayes I included it in the PR for people who don't want to run the code but still want to see the output of tests passing.

Collaborator

rw commented Aug 30, 2018

@phayes I included it in the PR for people who don't want to run the code but still want to see the output of tests passing.

@aardappel

WOW! This is some amazing effort, the most comprehensive language port yet!

I'm missing Rust specific changes to Tutorial.md, and a Rust sample in samples. Here is a sample checklist to see if you've touched all typical language port files: 4898809

Show resolved Hide resolved CMakeLists.txt
Show outdated Hide outdated docs/source/RustUsage.md
Show outdated Hide outdated docs/source/RustUsage.md
Show outdated Hide outdated rust/flatbuffers/src/builder.rs
Show outdated Hide outdated rust/flatbuffers/src/builder.rs
@@ -14,8 +14,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
../flatc --cpp --java --csharp --dart --go --binary --lobster --lua --python --js --ts --php --grpc --gen-mutable --reflect-names --gen-object-api --no-includes --cpp-ptr-type flatbuffers::unique_ptr --no-fb-import -I include_test monster_test.fbs monsterdata_test.json
../flatc --cpp --java --csharp --dart --go --binary --lobster --lua --python --js --ts --php --gen-mutable --reflect-names --no-fb-import --cpp-ptr-type flatbuffers::unique_ptr -o namespace_test namespace_test/namespace_test1.fbs namespace_test/namespace_test2.fbs
../flatc --cpp --java --csharp --dart --go --binary --lobster --lua --python --js --ts --php --rust --grpc --gen-mutable --reflect-names --gen-object-api --no-includes --cpp-ptr-type flatbuffers::unique_ptr --no-fb-import -I include_test monster_test.fbs monsterdata_test.json

This comment has been minimized.

@aardappel

aardappel Aug 30, 2018

Collaborator

please change .bat as well

@aardappel

aardappel Aug 30, 2018

Collaborator

please change .bat as well

This comment has been minimized.

@rw

rw Sep 2, 2018

Collaborator

Updated

@rw

rw Sep 2, 2018

Collaborator

Updated

impl<'a> flatbuffers::Follow<'a> for Monster<'a> {
type Inner = Monster<'a>;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {

This comment has been minimized.

@aardappel

aardappel Aug 30, 2018

Collaborator

should this be _follow if there is a possibility of a clash with generated fields?

@aardappel

aardappel Aug 30, 2018

Collaborator

should this be _follow if there is a possibility of a clash with generated fields?

This comment has been minimized.

@rw

rw Sep 2, 2018

Collaborator

Good eye! This is actually okay because it's a trait method, so unless users are importing Push, they cannot access it. Furthermore, I added the trait methods we use to the reserved keywords list, so a field called follow would be generated as follow_.

@rw

rw Sep 2, 2018

Collaborator

Good eye! This is actually okay because it's a trait method, so unless users are importing Push, they cannot access it. Furthermore, I added the trait methods we use to the reserved keywords list, so a field called follow would be generated as follow_.

Show outdated Hide outdated tests/rust_usage_test/test_bench_output.txt
Show outdated Hide outdated tests/rust_usage_test/tests/integration_test.rs
Show outdated Hide outdated tests/rust_usage_test/tests/integration_test.rs

rw added some commits Sep 2, 2018

@rw

This comment has been minimized.

Show comment
Hide comment
@rw

rw Sep 2, 2018

Collaborator

@aardappel Thanks for the feedback, I incorporated it all. Also, I resolved an alignment issue that I didn't catch before, and made the Push trait more useful.

Collaborator

rw commented Sep 2, 2018

@aardappel Thanks for the feedback, I incorporated it all. Also, I resolved an alignment issue that I didn't catch before, and made the Push trait more useful.

@aardappel aardappel merged commit 0758c1e into google:master Sep 3, 2018

3 checks passed

cla/google All necessary CLAs are signed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@aardappel

This comment has been minimized.

Show comment
Hide comment
@aardappel

aardappel Sep 3, 2018

Collaborator

Thanks! Amazing work!

Collaborator

aardappel commented Sep 3, 2018

Thanks! Amazing work!

rw added a commit that referenced this pull request Sep 3, 2018

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.

rw added a commit that referenced this pull request Sep 3, 2018

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.
@binary132

This comment has been minimized.

Show comment
Hide comment
@binary132

binary132 Sep 3, 2018

👏 👏 👏

binary132 commented Sep 3, 2018

👏 👏 👏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment