mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-12 07:50:59 +00:00
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:
38
tests/rust_usage_test/outdir/src/main.rs
Normal file
38
tests/rust_usage_test/outdir/src/main.rs
Normal 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()
|
||||
}
|
||||
Reference in New Issue
Block a user