summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWilliam Bain <bain.william.a@gmail.com>2021-01-25 12:33:47 -0500
committerGitHub <noreply@github.com>2021-01-25 09:33:47 -0800
commitefcbdc7698987643ed713a9285f81863b4000f05 (patch)
tree301645e98a94f3254d1f7da69e58f2b205177a7a /src
parente581013e3d42af13d2fe37b0ac46a3fd43f3638c (diff)
downloadflatbuffers-efcbdc7698987643ed713a9285f81863b4000f05.tar.gz
flatbuffers-efcbdc7698987643ed713a9285f81863b4000f05.tar.bz2
flatbuffers-efcbdc7698987643ed713a9285f81863b4000f05.zip
[Rust] Ensure unions are referenced with the correct path (#6422)
* Add codegen test for namespaced unions * [Rust] Handle cross-namespace union use * [Rust] Test namespace handling * [Rust] Drop trailing whitespace in codegen * [Rust] Set flags in generate_code.bat to match .sh * [C#] Add additional namespace test file
Diffstat (limited to 'src')
-rw-r--r--src/idl_gen_rust.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/idl_gen_rust.cpp b/src/idl_gen_rust.cpp
index 0bd27996..1677ce82 100644
--- a/src/idl_gen_rust.cpp
+++ b/src/idl_gen_rust.cpp
@@ -759,7 +759,7 @@ class RustGenerator : public BaseGenerator {
code_ += "impl flatbuffers::SimpleToVerifyInSlice for {{ENUM_NAME}} {}";
if (enum_def.is_union) {
- // Generate tyoesafe offset(s) for unions
+ // Generate typesafe offset(s) for unions
code_.SetValue("NAME", Name(enum_def));
code_.SetValue("UNION_OFFSET_NAME", Name(enum_def) + "UnionTableOffset");
code_ += "pub struct {{UNION_OFFSET_NAME}} {}";
@@ -808,7 +808,7 @@ class RustGenerator : public BaseGenerator {
// Get flatbuffers union key.
// CASPER: add docstrings?
- code_ += " fn {{ENUM_NAME_SNAKE}}_type(&self) -> {{ENUM_NAME}} {";
+ code_ += " pub fn {{ENUM_NAME_SNAKE}}_type(&self) -> {{ENUM_NAME}} {";
code_ += " match self {";
code_ += " Self::NONE => {{ENUM_NAME}}::NONE,";
ForAllUnionObjectVariantsBesidesNone(enum_def, [&] {
@@ -1501,8 +1501,8 @@ class RustGenerator : public BaseGenerator {
case ftUnionKey: return;
case ftUnionValue: {
const auto &enum_def = *type.enum_def;
- code_.SetValue("ENUM_NAME", Name(enum_def));
- code_.SetValue("NATIVE_ENUM_NAME", NativeName(enum_def));
+ code_.SetValue("ENUM_NAME", WrapInNameSpace(enum_def));
+ code_.SetValue("NATIVE_ENUM_NAME", NamespacedNativeName(enum_def));
code_ +=
" let {{FIELD_NAME}} = match "
"self.{{FIELD_NAME}}_type() {";
@@ -1730,7 +1730,7 @@ class RustGenerator : public BaseGenerator {
}
// Unions.
EnumDef &union_def = *field.value.type.enum_def;
- code_.SetValue("UNION_TYPE", Name(union_def));
+ code_.SetValue("UNION_TYPE", WrapInNameSpace(union_def));
code_ +=
"\n .visit_union::<{{UNION_TYPE}}, _>("
"&\"{{FIELD_NAME}}_type\", Self::{{OFFSET_NAME}}_TYPE, "
@@ -1878,7 +1878,7 @@ class RustGenerator : public BaseGenerator {
code_ += " }";
code_ += " },";
});
- code_ += " _ => { ";
+ code_ += " _ => {";
code_ += " let x: Option<()> = None;";
code_ += " ds.field(\"{{FIELD_NAME}}\", &x)";
code_ += " },";