mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-08 06:05:17 +00:00
[Rust] Add gen-name-strings for Rust (#5757)
* Add gen-name-strings for Rust * Clang format * Add tests and generate with gen-name-strings * Clang-format * Stop doing gen-name-strings with C++ code * Bring generate_code.bat up with generate_code.sh
This commit is contained in:
@@ -1127,6 +1127,16 @@ class RustGenerator : public BaseGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
// Generates a fully-qualified name getter for use with --gen-name-strings
|
||||
void GenFullyQualifiedNameGetter(const StructDef &struct_def,
|
||||
const std::string &name) {
|
||||
code_ += " pub const fn get_fully_qualified_name() -> &'static str {";
|
||||
code_ += " \"" +
|
||||
struct_def.defined_namespace->GetFullyQualifiedName(name) + "\"";
|
||||
code_ += " }";
|
||||
code_ += "";
|
||||
}
|
||||
|
||||
// Generate an accessor struct, builder struct, and create function for a
|
||||
// table.
|
||||
void GenTable(const StructDef &struct_def) {
|
||||
@@ -1157,6 +1167,11 @@ class RustGenerator : public BaseGenerator {
|
||||
code_ += "}";
|
||||
code_ += "";
|
||||
code_ += "impl<'a> {{STRUCT_NAME}}<'a> {";
|
||||
|
||||
if (parser_.opts.generate_name_strings) {
|
||||
GenFullyQualifiedNameGetter(struct_def, struct_def.name);
|
||||
}
|
||||
|
||||
code_ += " #[inline]";
|
||||
code_ +=
|
||||
" pub fn init_from_table(table: flatbuffers::Table<'a>) -> "
|
||||
@@ -1728,6 +1743,10 @@ class RustGenerator : public BaseGenerator {
|
||||
code_ += " }";
|
||||
code_ += " }";
|
||||
|
||||
if (parser_.opts.generate_name_strings) {
|
||||
GenFullyQualifiedNameGetter(struct_def, struct_def.name);
|
||||
}
|
||||
|
||||
// Generate accessor methods for the struct.
|
||||
for (auto it = struct_def.fields.vec.begin();
|
||||
it != struct_def.fields.vec.end(); ++it) {
|
||||
|
||||
Reference in New Issue
Block a user