Rust: remove inner attributes (#6410)

* 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>
This commit is contained in:
Casper
2021-01-26 11:09:29 -05:00
committed by GitHub
parent efcbdc7698
commit 6effe431bb
15 changed files with 104 additions and 9 deletions

View File

@@ -0,0 +1,38 @@
// In this example, a build.rs file generates the code and then copies it into $OUT_DIR.
extern crate flatbuffers;
#[cfg(target_family = "unix")]
#[allow(dead_code, unused_imports)]
mod generated {
include!(concat!(env!("OUT_DIR"), "/monster_generated.rs"));
}
#[cfg(target_family = "windows")]
#[allow(dead_code, unused_imports)]
mod generated {
include!(concat!(env!("OUT_DIR"), "\\monster_generated.rs"));
}
use generated::my_game::sample::{Monster, MonsterArgs};
fn main() {
let mut fbb = flatbuffers::FlatBufferBuilder::new();
let name = Some(fbb.create_string("bob"));
let m = Monster::create(&mut fbb, &MonsterArgs {
hp: 1,
mana: 2,
name,
..Default::default()
});
fbb.finish(m, None);
let mon = flatbuffers::root::<Monster>(fbb.finished_data()).unwrap();
assert_eq!(mon.hp(), 1);
assert_eq!(mon.mana(), 2);
assert_eq!(mon.name().unwrap(), "bob");
}
#[test]
fn test_main() {
main()
}