Skip to content

Commit

Permalink
include group oneof variants in generated output
Browse files Browse the repository at this point in the history
  • Loading branch information
kristopherbullinger committed Oct 3, 2024
1 parent c44f053 commit 7919ee0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion protobuf-codegen/src/gen/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ impl<'a> MessageGen<'a> {
F: Fn(&mut CodeWriter, &OneofVariantGen, &RustValueTyped),
{
for oneof in self.oneofs() {
let variants = oneof.variants_except_group();
let variants = oneof.variants();
if variants.is_empty() {
// Special case because
// https://github.com/rust-lang/rust/issues/50642
Expand Down
26 changes: 15 additions & 11 deletions protobuf-codegen/src/gen/oneof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,17 +223,21 @@ impl<'a> OneofGen<'a> {
.collect()
}

pub fn variants(&'a self) -> impl Iterator<Item = OneofVariantGen<'a>> {
self.oneof.variants().into_iter().map(|v| {
let field = self
.message
.fields
.iter()
.filter(|f| f.proto_field.name() == v.field.name())
.next()
.expect(&format!("field not found by name: {}", v.field.name()));
OneofVariantGen::parse(self, v, field, self.message.root_scope)
})
pub fn variants(&'a self) -> Vec<OneofVariantGen<'a>> {
self.oneof
.variants()
.into_iter()
.map(|v| {
let field = self
.message
.fields
.iter()
.filter(|f| f.proto_field.name() == v.field.name())
.next()
.expect(&format!("field not found by name: {}", v.field.name()));
OneofVariantGen::parse(self, v, field, self.message.root_scope)
})
.collect()
}

pub fn full_storage_type(&self) -> RustType {
Expand Down

0 comments on commit 7919ee0

Please sign in to comment.