Skip to content
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
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
93f9162
Port FlatBuffers to Rust: generator/runtime/tests.
rw Aug 29, 2018
66c6440
add idl_gen_rust.cpp to BUILD
rw Aug 31, 2018
d608827
remove the duplicate function `fill` and add some inline attributes
rw Aug 31, 2018
596017e
add comment in docs that Rust might add a verifier in the future
rw Aug 31, 2018
38b264c
generate tests/monsterdata_rust_wire.mon during rust tests (and gitig…
rw Aug 31, 2018
80725be
add rust to flatbuffers.md docs
rw Aug 31, 2018
129dd2d
docs
rw Aug 31, 2018
a865717
simplify nested asserts
rw Aug 31, 2018
2ed43e0
refactor vtable writing
rw Aug 31, 2018
9499632
remove duplicate assert
rw Aug 31, 2018
5138f85
comment
rw Aug 31, 2018
71a5ea4
use size_of for constants
rw Aug 31, 2018
9ea510c
comment
rw Aug 31, 2018
9736b9f
use auto instead of std::string in many places in the rust generator
rw Aug 31, 2018
3e74948
update generate_code.bat with rust
rw Aug 31, 2018
52d43ca
comments on reserved keywords; indentation of union accessors
rw Aug 31, 2018
b5b4631
delete test output
rw Aug 31, 2018
b5e5096
comment to explain why we do not inline a struct creation
rw Aug 31, 2018
77fb225
refactor some tests with macros
rw Aug 31, 2018
47ebb61
add support column for rust
rw Aug 31, 2018
ee51cc0
ergonomics/lifetimes tweaks in builder
rw Sep 1, 2018
a78edd0
no more need for ZeroTerminatedByteSlice
rw Sep 1, 2018
67004f3
wip for making Push::size a static method
rw Sep 1, 2018
894fe3e
simplifying push some more
rw Sep 1, 2018
fb28cad
delete old test
rw Sep 1, 2018
bd33f75
inlining, push
rw Sep 1, 2018
a3ef1de
Push::size is static
rw Sep 1, 2018
87cef86
start_vector requires push
rw Sep 2, 2018
bd2a5ed
more push/vector typing
rw Sep 2, 2018
36de894
no more phantomdata
rw Sep 2, 2018
3c03f30
good sample and docs
rw Sep 2, 2018
0de4628
add a todo to rust lib
rw Sep 2, 2018
7972b79
regenerate rust test code
rw Sep 2, 2018
f070f53
more alignment/size tests
rw Sep 2, 2018
8081c5a
remove dead code
rw Sep 2, 2018
acf48d0
doc tweak
rw Sep 2, 2018
4d005c1
revert old typescript file to master
rw Sep 2, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ergonomics/lifetimes tweaks in builder
  • Loading branch information
rw committed Sep 1, 2018
commit ee51cc0b6302cbea6efdaaaeac897ffb220c8061
6 changes: 3 additions & 3 deletions rust/flatbuffers/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ impl<'fbb> FlatBufferBuilder<'fbb> {
///
/// The wire format represents this as a zero-terminated byte vector.
#[inline]
pub fn create_string(&mut self, s: &str) -> WIPOffset<&'fbb str> {
pub fn create_string<'a: 'b, 'b>(&'a mut self, s: &'b str) -> WIPOffset<&'fbb str> {
self.assert_not_nested("create_string can not be called when a table or vector is under construction");
self.push(ZeroTerminatedByteSlice::new(s.as_bytes()));
WIPOffset::new(self.used_space() as UOffsetT)
Expand All @@ -244,7 +244,7 @@ impl<'fbb> FlatBufferBuilder<'fbb> {
/// always safe, on any platform: bool, u8, i8, and any
/// FlatBuffers-generated struct.
#[inline]
pub fn create_vector_direct<T: SafeSliceAccess + Push + Sized>(&mut self, data: &[T]) -> WIPOffset<Vector<'fbb, T>> {
pub fn create_vector_direct<'a: 'b, 'b, T: SafeSliceAccess + Push + Sized + 'b>(&'a mut self, data: &'b [T]) -> WIPOffset<Vector<'fbb, T>> {
self.assert_not_nested("create_vector_direct can not be called when a table or vector is under construction");
self.push(data);
WIPOffset::new(self.used_space() as UOffsetT)
Expand Down Expand Up @@ -273,7 +273,7 @@ impl<'fbb> FlatBufferBuilder<'fbb> {
/// Speed-sensitive users may wish to reduce memory usage by creating the
/// vector manually: use `create_vector`, `push`, and `end_vector`.
#[inline]
pub fn create_vector<'a, T: Push + Copy + 'fbb>(&'a mut self, items: &'a [T]) -> WIPOffset<Vector<'fbb, T::Output>> {
pub fn create_vector<'a: 'b, 'b, T: Push + Copy + 'b>(&'a mut self, items: &'b [T]) -> WIPOffset<Vector<'fbb, T::Output>> {
let elemsize = size_of::<T>();
self.start_vector(elemsize, items.len());
// TODO(rw): precompute the space needed and call `make_space` only once
Expand Down
8 changes: 3 additions & 5 deletions tests/rust_usage_test/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,6 @@ fn create_serialized_example_with_generated_code(builder: &mut flatbuffers::Flat
let s0 = builder.create_string("test1");
let s1 = builder.create_string("test2");
let fred_name = builder.create_string("Fred");
let inventory = builder.create_vector_direct(&[0u8, 1, 2, 3, 4][..]);
let test4 = builder.create_vector_direct(&[my_game::example::Test::new(10, 20),
my_game::example::Test::new(30, 40)]);

// can't inline creation of this Vec3 because we refer to it by reference, so it must live
// long enough to be used by MonsterArgs.
Expand All @@ -101,8 +98,9 @@ fn create_serialized_example_with_generated_code(builder: &mut flatbuffers::Flat
name: Some(fred_name),
..Default::default()
}).as_union_value()),
inventory: Some(inventory),
test4: Some(test4),
inventory: Some(builder.create_vector_direct(&[0u8, 1, 2, 3, 4][..])),
test4: Some(builder.create_vector_direct(&[my_game::example::Test::new(10, 20),
my_game::example::Test::new(30, 40)])),
testarrayofstring: Some(builder.create_vector(&[s0, s1])),
..Default::default()
};
Expand Down