diff options
author | kzvi <38590027+kzvi@users.noreply.github.com> | 2018-09-27 20:56:49 -0700 |
---|---|---|
committer | Robert <rw@users.noreply.github.com> | 2018-09-27 20:56:49 -0700 |
commit | a89be8739c462b47d59e1364e3e2dc8096806400 (patch) | |
tree | 9d89f7d8abf1dd50c0ceb0460a050b160b52b3a2 /tests/rust_usage_test | |
parent | 0bffce5aefee03f8e52aa77cc0154772236adad5 (diff) | |
download | flatbuffers-a89be8739c462b47d59e1364e3e2dc8096806400.tar.gz flatbuffers-a89be8739c462b47d59e1364e3e2dc8096806400.tar.bz2 flatbuffers-a89be8739c462b47d59e1364e3e2dc8096806400.zip |
loosen lifetimes in type signature of Table::get (#4925)
Diffstat (limited to 'tests/rust_usage_test')
-rw-r--r-- | tests/rust_usage_test/tests/integration_test.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/rust_usage_test/tests/integration_test.rs b/tests/rust_usage_test/tests/integration_test.rs index 0e5f8fac..ca55f652 100644 --- a/tests/rust_usage_test/tests/integration_test.rs +++ b/tests/rust_usage_test/tests/integration_test.rs @@ -235,6 +235,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; |