@ -37,7 +37,7 @@ namespace rust {
// Example:
// For this oneof:
// message SomeMsg {
// oneof some_oneof {
// oneof some {
// int32 field_a = 7;
// SomeMsg field_b = 9;
// }
@ -52,7 +52,7 @@ namespace rust {
// }
//
// #[repr(C)]
// pub enum SomeOneof Case {
// pub enum SomeCase {
// FieldA = 7,
// FieldB = 9,
// not_set = 0
@ -60,25 +60,15 @@ namespace rust {
// }
// impl SomeMsg {
// pub fn some_oneof(&self) -> SomeOneof {...}
// pub fn some_oneof_case(&self) -> SomeOneof Case {...}
// pub fn some_oneof_case(&self) -> SomeCase {...}
// }
// impl SomeMsgMut {
// pub fn some_oneof(&self) -> SomeOneof {...}
// pub fn some_oneof_case(&self) -> SomeOneof Case {...}
// pub fn some_oneof_case(&self) -> SomeCase {...}
// }
// impl SomeMsgView {
// pub fn some_oneof(self) -> SomeOneof {...}
// pub fn some_oneof_case(self) -> SomeOneofCase {...}
// }
//
// An additional "Case" enum which just reflects the corresponding slot numbers
// is emitted for usage with the FFI (exactly matching the Case struct that both
// cpp and upb generate).
//
// #[repr(C)] pub(super) enum SomeOneofCase {
// FieldA = 7,
// FieldB = 9,
// not_set = 0
// pub fn some_oneof_case(self) -> SomeCase {...}
// }
namespace {
@ -134,6 +124,7 @@ std::string RsTypeNameView(Context& ctx, const FieldDescriptor& field) {
void GenerateOneofDefinition ( Context & ctx , const OneofDescriptor & oneof ) {
ctx . Emit (
{
{ " deprecated_view_enum_name " , DeprecatedOneofViewEnumRsName ( oneof ) } ,
{ " view_enum_name " , OneofViewEnumRsName ( oneof ) } ,
{ " view_fields " ,
[ & ] {
@ -164,9 +155,11 @@ void GenerateOneofDefinition(Context& ctx, const OneofDescriptor& oneof) {
pub enum $ view_enum_name $ < ' msg > {
$ view_fields $
# [allow(non_camel_case_types)]
not_set ( std : : marker : : PhantomData < & ' msg ( ) > ) = 0
}
# [deprecated(note="Use $view_enum_name$ instead (will be imminently moved)")]
pub use $ view_enum_name $ as $ deprecated_view_enum_name $ ;
) rs " );
// Note: This enum is used as the Thunk return type for getting which case is
@ -205,7 +198,6 @@ void GenerateOneofDefinition(Context& ctx, const OneofDescriptor& oneof) {
pub enum $ case_enum_name $ {
$ cases $
# [allow(non_camel_case_types)]
not_set = 0
}
@ -313,7 +305,7 @@ void GenerateOneofThunkCc(Context& ctx, const OneofDescriptor& oneof) {
ctx . Emit (
{
{ " oneof_name " , oneof . name ( ) } ,
{ " case_enum_name " , OneofCaseEnumRs Name ( oneof ) } ,
{ " case_enum_name " , OneofCaseEnumCpp Name ( oneof ) } ,
{ " case_thunk " , ThunkName ( ctx , oneof , " case " ) } ,
{ " QualifiedMsg " , cpp : : QualifiedClassName ( oneof . containing_type ( ) ) } ,
} ,