include_prefix support for rust (#6330)
authorKamil Rojewski <kamil.rojewski@gmail.com>
Wed, 30 Dec 2020 20:02:36 +0000 (21:02 +0100)
committerGitHub <noreply@github.com>
Wed, 30 Dec 2020 20:02:36 +0000 (12:02 -0800)
* include_prefix support for rust

* include_prefix support for java

* formatting fixes

* Revert "include_prefix support for java"

* style fix

src/idl_gen_rust.cpp

index 04c779d..4e504cd 100644 (file)
@@ -1907,8 +1907,16 @@ class RustGenerator : public BaseGenerator {
         auto noext = flatbuffers::StripExtension(it->second);
         auto basename = flatbuffers::StripPath(noext);
 
-        code_ += indent + "use crate::" + basename +
-                 parser_.opts.filename_suffix + "::*;";
+        if (parser_.opts.include_prefix.empty()) {
+          code_ += indent + "use crate::" + basename +
+                   parser_.opts.filename_suffix + "::*;";
+        } else {
+          auto prefix = parser_.opts.include_prefix;
+          prefix.pop_back();
+
+          code_ += indent + "use crate::" + prefix + "::" + basename +
+                   parser_.opts.filename_suffix + "::*;";
+        }
       }
     }