mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-02 04:04:19 +00:00
[Rust] Add crate-relative use statements for FBS includes.
At present if a flatbuffer description includes a reference to a type in another file, the generated Rust code needs to be hand-modified to add the appropriate `use` statements. This assumes that the dependencies are built into the same crate, which I think is a reasonable assumption?
This commit is contained in:
@@ -1752,6 +1752,14 @@ class RustGenerator : public BaseGenerator {
|
||||
void GenNamespaceImports(const int white_spaces) {
|
||||
std::string indent = std::string(white_spaces, ' ');
|
||||
code_ += "";
|
||||
for (auto it = parser_.included_files_.begin();
|
||||
it != parser_.included_files_.end(); ++it) {
|
||||
if (it->second.empty()) continue;
|
||||
auto noext = flatbuffers::StripExtension(it->second);
|
||||
auto basename = flatbuffers::StripPath(noext);
|
||||
|
||||
code_ += indent + "use crate::" + basename + "_generated::*;";
|
||||
}
|
||||
code_ += indent + "use std::mem;";
|
||||
code_ += indent + "use std::cmp::Ordering;";
|
||||
code_ += "";
|
||||
|
||||
Reference in New Issue
Block a user