...

Text file src/github.com/google/flatbuffers/tests/rust_usage_test/bin/monster_example.rs

Documentation: github.com/google/flatbuffers/tests/rust_usage_test/bin

     1#![allow(clippy::derivable_impls, clippy::all)]
     2extern crate flatbuffers;
     3
     4
     5#[allow(dead_code, unused_imports)]
     6#[path = "../../include_test1/mod.rs"]
     7pub mod include_test1_generated;
     8
     9#[allow(dead_code, unused_imports)]
    10#[path = "../../include_test2/mod.rs"]
    11pub mod include_test2_generated;
    12
    13#[allow(dead_code, unused_imports, clippy::approx_constant)]
    14#[path = "../../monster_test/mod.rs"]
    15mod monster_test_generated;
    16pub use monster_test_generated::my_game;
    17
    18use std::io::Read;
    19
    20fn main() {
    21    let mut f = std::fs::File::open("../monsterdata_test.mon").unwrap();
    22    let mut buf = Vec::new();
    23    f.read_to_end(&mut buf).expect("file reading failed");
    24
    25    let monster = my_game::example::root_as_monster(&buf[..]).unwrap();
    26    println!("{}", monster.hp()); // `80`
    27    println!("{}", monster.mana()); // default value of `150`
    28    println!("{:?}", monster.name()); // Some("MyMonster")
    29}

View as plain text