Skip to content

Commit 92156f5

Browse files
committed
also support unions and groups
1 parent 412adb3 commit 92156f5

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

capnpc/rust.capnp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@0x83b3c14c3c8dd083;
22

3-
annotation name @0xc2fe4c6d100166d0 (field, struct, enum, enumerant) :Text;
3+
annotation name @0xc2fe4c6d100166d0 (field, struct, enum, enumerant, union, group) :Text;
44
# Rename something in the generated code. The value that you specify in this
55
# annotion must follow capnp capitalization conventions. So, for example,
66
# a struct could be named `StructFoo`, even though that will get translated

capnpc/test/test.capnp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,4 +771,12 @@ struct TestNameAnnotation $Rust.name("RenamedStruct") {
771771
grault @2 $Rust.name("garply");
772772
}
773773
}
774+
775+
badlyNamedUnion :union $Rust.name("renamedUnion") {
776+
badlyNamedGroup :group $Rust.name("renamedGroup") {
777+
foo @3 :Void;
778+
bar @4 :Void;
779+
}
780+
baz @5 :NestedStruct $Rust.name("qux");
781+
}
774782
}

capnpc/test/test.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,6 +1482,9 @@ mod tests {
14821482
let mut root: renamed_struct::Builder = message.init_root();
14831483
root.set_good_field_name(true);
14841484
root.set_another_good_field_name(renamed_struct::RenamedEnum::Bar);
1485+
1486+
let renamed_union = root.get_renamed_union();
1487+
renamed_union.init_qux();
14851488
}
14861489
{
14871490
let root: renamed_struct::Reader = message.get_root_as_reader().unwrap();
@@ -1490,6 +1493,12 @@ mod tests {
14901493
_ => panic!("expected GoodFieldName(true)"),
14911494
}
14921495
assert!(renamed_struct::RenamedEnum::Bar == root.get_another_good_field_name().unwrap());
1496+
1497+
1498+
match root.get_renamed_union().which().unwrap() {
1499+
renamed_struct::renamed_union::Qux(_) => (),
1500+
_ => panic!("expected Qux"),
1501+
}
14931502
}
14941503
}
14951504
}

0 commit comments

Comments
 (0)