forked from BigfootDev/flatbuffers
* Refactored Rust Generated code into a module directory. Each symbol will be generated into one file and then imported into a module. This breaks the "out_dir" pattern where some users would generate code in their target/ directory. Also, these objects are best used in their own module. It will be hard for users to share their own module structure with flatbuffers namespaces. There may be solutions to these drawbacks but that should be discussed. I don't want to overengineer here. * shadow error * try fix .bat file * fix .bat 2 * Restore accidentally deleted files * Fixed some DONOTSUBMITs and made Rust outdir pattern use symlinks. * fixed binary files * git clang format * make generated onefiles not public and fix .bat * reduced diff with master in generate_code.sh * fix shadowed variable * add object api flags to .bat * space * Removed extern crate and extra & * use statement * more clippy lints * format * Undo extern crate -> use change, it actually matters to our tests Co-authored-by: Casper Neo <cneo@google.com>
28 lines
846 B
Rust
28 lines
846 B
Rust
extern crate flatbuffers;
|
|
|
|
#[allow(dead_code, unused_imports)]
|
|
#[path = "../../include_test1/mod.rs"]
|
|
pub mod include_test1_generated;
|
|
|
|
#[allow(dead_code, unused_imports)]
|
|
#[path = "../../include_test2/mod.rs"]
|
|
pub mod include_test2_generated;
|
|
|
|
#[allow(dead_code, unused_imports, clippy::approx_constant)]
|
|
#[path = "../../monster_test/mod.rs"]
|
|
mod monster_test_generated;
|
|
pub use monster_test_generated::my_game;
|
|
|
|
use std::io::Read;
|
|
|
|
fn main() {
|
|
let mut f = std::fs::File::open("../monsterdata_test.mon").unwrap();
|
|
let mut buf = Vec::new();
|
|
f.read_to_end(&mut buf).expect("file reading failed");
|
|
|
|
let monster = my_game::example::root_as_monster(&buf[..]).unwrap();
|
|
println!("{}", monster.hp()); // `80`
|
|
println!("{}", monster.mana()); // default value of `150`
|
|
println!("{:?}", monster.name()); // Some("MyMonster")
|
|
}
|