Repository: heremaps/flatdata (language: python)

Issue:
Simplify importing flatdata-rs
At the moment, to import flatdata in rust, we need to write:

```rust
#[macro_use]
extern crate flatdata
```

* We should try to remove this requirement.
* Also, nightly compiler fails due to missing `flatdata_intersperse` macro. 


Discussion / hints:
For the second point, see: https://github.com/rust-lang/rust/issues/63888. It's fixed in nightly but not yet in beta.
Is this still an issue? @boxdot  ?
Yes, minimal example:

```rust
#[macro_use]
extern crate flatdata;

include!(concat!(env!("OUT_DIR"), "/graph.rs"));

fn main() {
    println!("Hello, world!");
}
```

Looks like there is also a bug in the docs which tell to do:

```rust
#![allow(dead_code)]
include!(concat!(env!("OUT_DIR"), "/graph.rs"));
```

but the dead code annotation actually does not work.

Fix patch:
diff --git a/flatdata-generator/flatdata/generator/templates/rust/rust.jinja2 b/flatdata-generator/flatdata/generator/templates/rust/rust.jinja2
index 30af1b40..90277125 100644
--- a/flatdata-generator/flatdata/generator/templates/rust/rust.jinja2
+++ b/flatdata-generator/flatdata/generator/templates/rust/rust.jinja2
@@ -14,6 +14,9 @@
 #[allow(missing_docs)]
 {% endif %}
 pub mod {{ ns.name }} {
+#[allow(unused_imports)]
+use flatdata::{flatdata_read_bytes, flatdata_write_bytes};
+
 {{ loop(ns.children) }}
 {%- for node in ns.children %}
     {% if node | is_structure and not node | is_multivector_index %}


Test patch:
diff --git a/flatdata-generator/tests/generators/rust_expectations/archives/multivector.rs.2 b/flatdata-generator/tests/generators/rust_expectations/archives/multivector.rs.2
index 29bdcd16..038ac3b6 100644
--- a/flatdata-generator/tests/generators/rust_expectations/archives/multivector.rs.2
+++ b/flatdata-generator/tests/generators/rust_expectations/archives/multivector.rs.2
@@ -1,8 +1,14 @@
 #[doc(hidden)]
 pub mod _builtin {
+#[allow(unused_imports)]
+use flatdata::{flatdata_read_bytes, flatdata_write_bytes};
+
 
 #[allow(missing_docs)]
 pub mod multivector {
+#[allow(unused_imports)]
+use flatdata::{flatdata_read_bytes, flatdata_write_bytes};
+
 
 /// Builtin type to for MultiVector index
 #[repr(transparent)]
diff --git a/flatdata-generator/tests/generators/rust_expectations/archives/namespaces.rs.1 b/flatdata-generator/tests/generators/rust_expectations/archives/namespaces.rs.1
index fccb1e3f..9fa1f31b 100644
--- a/flatdata-generator/tests/generators/rust_expectations/archives/namespaces.rs.1
+++ b/flatdata-generator/tests/generators/rust_expectations/archives/namespaces.rs.1
@@ -1,4 +1,8 @@
+#[allow(missing_docs)]
 pub mod n {
+#[allow(unused_imports)]
+use flatdata::{flatdata_read_bytes, flatdata_write_bytes};
+
 #[repr(transparent)]
 #[derive(Clone)]
 pub struct S {
@@ -221,6 +225,9 @@ archive X
 
 #[allow(missing_docs)]
 pub mod m {
+#[allow(unused_imports)]
+use flatdata::{flatdata_read_bytes, flatdata_write_bytes};
+
 #[repr(transparent)]
 #[derive(Clone)]
 pub struct S {
@@ -443,6 +450,9 @@ archive X
 
 #[allow(missing_docs)]
 pub mod a {
+#[allow(unused_imports)]
+use flatdata::{flatdata_read_bytes, flatdata_write_bytes};
+
 
 
 /// Enum for read-only heterogeneous access to elements in a
@@ -814,9 +824,15 @@ archive A
 
 #[doc(hidden)]
 pub mod _builtin {
+#[allow(unused_imports)]
+use flatdata::{flatdata_read_bytes, flatdata_write_bytes};
+
 
 #[allow(missing_docs)]
 pub mod multivector {
+#[allow(unused_imports)]
+use flatdata::{flatdata_read_bytes, flatdata_write_bytes};
+
 
 /// Builtin type to for MultiVector index
 #[repr(transparent)]
diff --git a/flatdata-generator/tests/generators/rust_expectations/archives/references.rs.1 b/flatdata-generator/tests/generators/rust_expectations/archives/references.rs.1
index 9709e482..37c74825 100644
--- a/flatdata-generator/tests/generators/rust_expectations/archives/references.rs.1
+++ b/flatdata-generator/tests/generators/rust_expectations/archives/references.rs.1
@@ -1,6 +1,9 @@
 // Do not edit: This code was generated by flatdata's generator.
 #[allow(missing_docs)]
 pub mod n {
+#[allow(unused_imports)]
+use flatdata::{flatdata_read_bytes, flatdata_write_bytes};
+
 #[repr(transparent)]
 #[derive(Clone)]
 pub struct S {
@@ -1020,9 +1023,15 @@ archive A
 
 #[doc(hidden)]
 pub mod _builtin {
+#[allow(unused_imports)]
+use flatdata::{flatdata_read_bytes, flatdata_write_bytes};
+
 
 #[allow(missing_docs)]
 pub mod multivector {
+#[allow(unused_imports)]
+use flatdata::{flatdata_read_bytes, flatdata_write_bytes};
+
 
 /// Builtin type to for MultiVector index
 #[repr(transparent)]
diff --git a/flatdata-generator/tests/generators/rust_expectations/constants/namespaces.rs.1 b/flatdata-generator/tests/generators/rust_expectations/constants/namespaces.rs.1
index 0ede1a6b..c98de177 100644
--- a/flatdata-generator/tests/generators/rust_expectations/constants/namespaces.rs.1
+++ b/flatdata-generator/tests/generators/rust_expectations/constants/namespaces.rs.1
@@ -1,4 +1,7 @@
 pub mod n {
+#[allow(unused_imports)]
+use flatdata::{flatdata_read_bytes, flatdata_write_bytes};
+
 
 pub const FOO: i8 = 0;
 
@@ -11,5 +14,8 @@ pub mod schema {
 
 #[allow(missing_docs)]
 pub mod m {
+#[allow(unused_imports)]
+use flatdata::{flatdata_read_bytes, flatdata_write_bytes};
+
 
 pub const FOO: i8 = 1;
diff --git a/flatdata-generator/tests/generators/rust_expectations/enums/namespaces.rs.1 b/flatdata-generator/tests/generators/rust_expectations/enums/namespaces.rs.1
index f8bc3138..93c6eab5 100644
--- a/flatdata-generator/tests/generators/rust_expectations/enums/namespaces.rs.1
+++ b/flatdata-generator/tests/generators/rust_expectations/enums/namespaces.rs.1
@@ -1,4 +1,7 @@
 pub mod a {
+#[allow(unused_imports)]
+use flatdata::{flatdata_read_bytes, flatdata_write_bytes};
+
 #[derive(Debug, PartialEq, Eq)]
 #[repr(u8)]
 pub enum Bar {
@@ -18,6 +21,9 @@ pub mod schema {
 
 #[allow(missing_docs)]
 pub mod b {
+#[allow(unused_imports)]
+use flatdata::{flatdata_read_bytes, flatdata_write_bytes};
+
 #[derive(Debug, PartialEq, Eq)]
 #[repr(u8)]
 pub enum Bar {
@@ -37,6 +43,9 @@ pub mod schema {
 
 #[allow(missing_docs)]
 pub mod n {
+#[allow(unused_imports)]
+use flatdata::{flatdata_read_bytes, flatdata_write_bytes};
+
 #[repr(transparent)]
 #[derive(Clone)]
 pub struct Foo {
@@ -158,6 +167,9 @@ pub mod schema {
 
 #[allow(missing_docs)]
 pub mod m {
+#[allow(unused_imports)]
+use flatdata::{flatdata_read_bytes, flatdata_write_bytes};
+
 #[repr(transparent)]
 #[derive(Clone)]
 pub struct Foo {
diff --git a/flatdata-generator/tests/generators/rust_expectations/structs/namespaces.rs.1 b/flatdata-generator/tests/generators/rust_expectations/structs/namespaces.rs.1
index 617273f1..fa951930 100644
--- a/flatdata-generator/tests/generators/rust_expectations/structs/namespaces.rs.1
+++ b/flatdata-generator/tests/generators/rust_expectations/structs/namespaces.rs.1
@@ -119,6 +119,9 @@ pub mod schema {
 
 #[allow(missing_docs)]
 pub mod m {
+#[allow(unused_imports)]
+use flatdata::{flatdata_read_bytes, flatdata_write_bytes};
+
 #[repr(transparent)]
 #[derive(Clone)]
 pub struct Foo {
diff --git a/flatdata-rs/tests/coappearances/src/lib.rs b/flatdata-rs/tests/coappearances/src/lib.rs
index b274a5fa..20f4aa44 100644
--- a/flatdata-rs/tests/coappearances/src/lib.rs
+++ b/flatdata-rs/tests/coappearances/src/lib.rs
@@ -1,8 +1,5 @@
 #![cfg(test)]
 
-#[macro_use]
-extern crate flatdata;
-
 use std::{env, fs, io::Read, path, str};
 
 pub mod coappearances;
diff --git a/flatdata-rs/tests/features/src/lib.rs b/flatdata-rs/tests/features/src/lib.rs
index 14d73ea9..ee9149cb 100644
--- a/flatdata-rs/tests/features/src/lib.rs
+++ b/flatdata-rs/tests/features/src/lib.rs
@@ -4,6 +4,3 @@ pub mod archives;
 pub mod constants;
 pub mod enums;
 pub mod structs;
-
-#[macro_use]
-extern crate flatdata;