// automatically generated by the FlatBuffers compiler, do not modify
-#![allow(unused_imports, dead_code)]
use std::mem;
use std::cmp::Ordering;
extern crate flatbuffers;
// import the generated code
+#[allow(dead_code, unused_imports)]
#[path = "./monster_generated.rs"]
#[allow(clippy::approx_constant)] // We use low precision PI as a default value.
mod monster_generated;
}
void GenNamespaceImports(const int white_spaces) {
- if (white_spaces == 0) { code_ += "#![allow(unused_imports, dead_code)]"; }
+ // DO not use global attributes (i.e. #![...]) since it interferes
+ // with users who include! generated files.
+ // See: https://github.com/google/flatbuffers/issues/6261
std::string indent = std::string(white_spaces, ' ');
code_ += "";
if (!parser_.opts.generate_all) {
cargo bench $TARGET_FLAG
+# This test is dependent on flatc.
+if [[ -f ../../flatc ]]; then
+ cd outdir
+ cargo test
+ check_test_result "Rust generated file in \$OUT_DIR"
+ cd ..
+fi
+
# RUST_NIGHTLY environment variable set in dockerfile.
if [[ $RUST_NIGHTLY == 1 ]]; then
rustup +nightly component add miri
// automatically generated by the FlatBuffers compiler, do not modify
-#![allow(unused_imports, dead_code)]
use crate::include_test2_generated::*;
use std::mem;
// automatically generated by the FlatBuffers compiler, do not modify
-#![allow(unused_imports, dead_code)]
use crate::include_test1_generated::*;
use std::mem;
// automatically generated by the FlatBuffers compiler, do not modify
-#![allow(unused_imports, dead_code)]
use crate::include_test1_generated::*;
use crate::include_test2_generated::*;
// automatically generated by the FlatBuffers compiler, do not modify
-#![allow(unused_imports, dead_code)]
use std::mem;
use std::cmp::Ordering;
// automatically generated by the FlatBuffers compiler, do not modify
-#![allow(unused_imports, dead_code)]
use std::mem;
use std::cmp::Ordering;
// automatically generated by the FlatBuffers compiler, do not modify
-#![allow(unused_imports, dead_code)]
use std::mem;
use std::cmp::Ordering;
name = "sample_flatbuffers"
path = "../../samples/sample_binary.rs"
-
[dev-dependencies]
quickcheck = "0.6"
# TODO(rw): look into moving to criterion.rs
--- /dev/null
+[package]
+name = "outdir"
+version = "0.1.0"
+authors = ["Casper Neo <cneo@google.com>"]
+edition = "2018"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+flatbuffers = { path = "../../../rust/flatbuffers" }
--- /dev/null
+fn main() {
+ use std::process::Command;
+
+ let project_root = std::env::current_dir()
+ .unwrap()
+ .parent() // flatbuffers/tests/rust_usage test
+ .unwrap()
+ .parent() // flatbuffers/tests
+ .unwrap()
+ .parent() // flatbuffers/
+ .unwrap()
+ .to_path_buf();
+
+ let sample_schema = {
+ let mut s = project_root.to_path_buf();
+ s.push("samples");
+ s.push("monster.fbs");
+ s
+ };
+
+ let flatc = {
+ let mut f = project_root.to_path_buf();
+ f.push("flatc");
+ f
+ };
+
+ let out_dir = std::path::Path::new(&std::env::var("OUT_DIR").unwrap()).to_path_buf();
+
+ Command::new(&flatc)
+ .arg("--rust")
+ .arg(&sample_schema)
+ .arg("--filename-suffix")
+ .arg("_gen")
+ .output()
+ .expect("Failed to generate file");
+
+ let genfile = "monster_gen.rs";
+ std::fs::rename(&genfile, out_dir.join("monster_generated.rs")).unwrap();
+}
--- /dev/null
+// 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()
+}
mod flexbuffers_tests;
mod optional_scalars_test;
+#[allow(dead_code, unused_imports)]
#[path = "../../include_test/include_test1_generated.rs"]
pub mod include_test1_generated;
+#[allow(dead_code, unused_imports)]
#[path = "../../include_test/sub/include_test2_generated.rs"]
pub mod include_test2_generated;
+#[allow(dead_code, unused_imports)]
#[path = "../../namespace_test/namespace_test1_generated.rs"]
pub mod namespace_test1_generated;
+#[allow(dead_code, unused_imports)]
#[path = "../../namespace_test/namespace_test2_generated.rs"]
pub mod namespace_test2_generated;
+#[allow(dead_code, unused_imports)]
#[path = "../../monster_test_generated.rs"]
mod monster_test_generated;
pub use monster_test_generated::my_game;