Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
F
flatbuffers
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
flatbuffers
Commits
a89be873
Commit
a89be873
authored
Sep 28, 2018
by
kzvi
Committed by
Robert
Sep 28, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
loosen lifetimes in type signature of Table::get (#4925)
parent
0bffce5a
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
2 deletions
+33
-2
table.rs
rust/flatbuffers/src/table.rs
+2
-2
integration_test.rs
tests/rust_usage_test/tests/integration_test.rs
+31
-0
No files found.
rust/flatbuffers/src/table.rs
View file @
a89be873
...
...
@@ -30,12 +30,12 @@ impl<'a> Table<'a> {
Table
{
buf
:
buf
,
loc
:
loc
}
}
#[inline]
pub
fn
vtable
(
&
'a
self
)
->
VTable
<
'a
>
{
pub
fn
vtable
(
&
self
)
->
VTable
<
'a
>
{
<
BackwardsSOffset
<
VTable
<
'a
>>>
::
follow
(
self
.buf
,
self
.loc
)
}
#[inline]
pub
fn
get
<
T
:
Follow
<
'a
>
+
'a
>
(
&
'a
self
,
&
self
,
slot_byte_loc
:
VOffsetT
,
default
:
Option
<
T
::
Inner
>
,
)
->
Option
<
T
::
Inner
>
{
...
...
tests/rust_usage_test/tests/integration_test.rs
View file @
a89be873
...
...
@@ -234,6 +234,37 @@ mod generated_constants {
}
}
#[cfg(test)]
mod
lifetime_correctness
{
extern
crate
flatbuffers
;
use
std
::
mem
;
use
super
::
my_game
;
use
super
::
load_file
;
#[test]
fn
table_get_field_from_static_buffer_1
()
{
let
buf
=
load_file
(
"../monsterdata_test.mon"
);
// create 'static slice
let
slice
:
&
[
u8
]
=
&
buf
;
let
slice
:
&
'static
[
u8
]
=
unsafe
{
mem
::
transmute
(
slice
)
};
// make sure values retrieved from the 'static buffer are themselves 'static
let
monster
:
my_game
::
example
::
Monster
<
'static
>
=
my_game
::
example
::
get_root_as_monster
(
slice
);
// this line should compile:
let
name
:
Option
<&
'static
str
>
=
monster
._tab.get
::
<
flatbuffers
::
ForwardsUOffset
<&
str
>>
(
my_game
::
example
::
Monster
::
VT_NAME
,
None
);
assert_eq!
(
name
,
Some
(
"MyMonster"
));
}
#[test]
fn
table_get_field_from_static_buffer_2
()
{
static
DATA
:
[
u8
;
4
]
=
[
0
,
0
,
0
,
0
];
// some binary data
let
table
:
flatbuffers
::
Table
<
'static
>
=
flatbuffers
::
Table
::
new
(
&
DATA
,
0
);
// this line should compile:
table
.get
::
<&
'static
str
>
(
0
,
None
);
}
}
#[cfg(test)]
mod
roundtrip_generated_code
{
extern
crate
flatbuffers
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment