|
|
|
@ -23,16 +23,19 @@ namespace rust { |
|
|
|
|
void RepeatedField::InMsgImpl(Context& ctx, const FieldDescriptor& field, |
|
|
|
|
AccessorCase accessor_case) const { |
|
|
|
|
std::string field_name = FieldNameWithCollisionAvoidance(field); |
|
|
|
|
ctx.Emit({{"field", RsSafeName(field_name)}, |
|
|
|
|
{"RsType", RsTypePath(ctx, field)}, |
|
|
|
|
{"view_lifetime", ViewLifetime(accessor_case)}, |
|
|
|
|
{"view_self", ViewReceiver(accessor_case)}, |
|
|
|
|
{"getter_thunk", ThunkName(ctx, field, "get")}, |
|
|
|
|
{"getter_mut_thunk", ThunkName(ctx, field, "get_mut")}, |
|
|
|
|
{"getter", |
|
|
|
|
[&] { |
|
|
|
|
if (ctx.is_upb()) { |
|
|
|
|
ctx.Emit({}, R"rs( |
|
|
|
|
ctx.Emit( |
|
|
|
|
{ |
|
|
|
|
{"field", RsSafeName(field_name)}, |
|
|
|
|
{"raw_field_name", field_name}, // Never r# prefixed
|
|
|
|
|
{"RsType", RsTypePath(ctx, field)}, |
|
|
|
|
{"view_lifetime", ViewLifetime(accessor_case)}, |
|
|
|
|
{"view_self", ViewReceiver(accessor_case)}, |
|
|
|
|
{"getter_thunk", ThunkName(ctx, field, "get")}, |
|
|
|
|
{"getter_mut_thunk", ThunkName(ctx, field, "get_mut")}, |
|
|
|
|
{"getter", |
|
|
|
|
[&] { |
|
|
|
|
if (ctx.is_upb()) { |
|
|
|
|
ctx.Emit({}, R"rs( |
|
|
|
|
pub fn $field$($view_self$) -> $pb$::RepeatedView<$view_lifetime$, $RsType$> { |
|
|
|
|
unsafe { |
|
|
|
|
$getter_thunk$( |
|
|
|
@ -47,8 +50,8 @@ void RepeatedField::InMsgImpl(Context& ctx, const FieldDescriptor& field, |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
)rs"); |
|
|
|
|
} else { |
|
|
|
|
ctx.Emit({}, R"rs( |
|
|
|
|
} else { |
|
|
|
|
ctx.Emit({}, R"rs( |
|
|
|
|
pub fn $field$($view_self$) -> $pb$::RepeatedView<$view_lifetime$, $RsType$> { |
|
|
|
|
unsafe { |
|
|
|
|
$pb$::RepeatedView::from_raw( |
|
|
|
@ -58,16 +61,16 @@ void RepeatedField::InMsgImpl(Context& ctx, const FieldDescriptor& field, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
)rs"); |
|
|
|
|
} |
|
|
|
|
}}, |
|
|
|
|
{"clearer_thunk", ThunkName(ctx, field, "clear")}, |
|
|
|
|
{"getter_mut", |
|
|
|
|
[&] { |
|
|
|
|
if (accessor_case == AccessorCase::VIEW) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (ctx.is_upb()) { |
|
|
|
|
ctx.Emit({}, R"rs( |
|
|
|
|
} |
|
|
|
|
}}, |
|
|
|
|
{"clearer_thunk", ThunkName(ctx, field, "clear")}, |
|
|
|
|
{"getter_mut", |
|
|
|
|
[&] { |
|
|
|
|
if (accessor_case == AccessorCase::VIEW) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (ctx.is_upb()) { |
|
|
|
|
ctx.Emit({}, R"rs( |
|
|
|
|
pub fn $field$_mut(&mut self) -> $pb$::RepeatedMut<'_, $RsType$> { |
|
|
|
|
unsafe { |
|
|
|
|
$pb$::RepeatedMut::from_inner( |
|
|
|
@ -85,8 +88,8 @@ void RepeatedField::InMsgImpl(Context& ctx, const FieldDescriptor& field, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
)rs"); |
|
|
|
|
} else { |
|
|
|
|
ctx.Emit({}, R"rs( |
|
|
|
|
} else { |
|
|
|
|
ctx.Emit({}, R"rs( |
|
|
|
|
pub fn $field$_mut(&mut self) -> $pb$::RepeatedMut<'_, $RsType$> { |
|
|
|
|
unsafe { |
|
|
|
|
$pb$::RepeatedMut::from_inner( |
|
|
|
@ -99,11 +102,25 @@ void RepeatedField::InMsgImpl(Context& ctx, const FieldDescriptor& field, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
)rs"); |
|
|
|
|
} |
|
|
|
|
}}}, |
|
|
|
|
R"rs( |
|
|
|
|
} |
|
|
|
|
}}, |
|
|
|
|
{"setter", |
|
|
|
|
[&] { |
|
|
|
|
if (accessor_case == AccessorCase::VIEW) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
ctx.Emit({}, R"rs( |
|
|
|
|
pub fn set_$raw_field_name$(&mut self, src: $pb$::RepeatedView<'_, $RsType$>) { |
|
|
|
|
// TODO: Implement IntoProxied and avoid copying.
|
|
|
|
|
self.$field$_mut().copy_from(src); |
|
|
|
|
} |
|
|
|
|
)rs"); |
|
|
|
|
}}, |
|
|
|
|
}, |
|
|
|
|
R"rs( |
|
|
|
|
$getter$ |
|
|
|
|
$getter_mut$ |
|
|
|
|
$setter$ |
|
|
|
|
)rs"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -180,6 +197,8 @@ void RepeatedField::InThunkCc(Context& ctx, |
|
|
|
|
{"clearer_thunk", ThunkName(ctx, field, "clear")}, |
|
|
|
|
{"getter_thunk", ThunkName(ctx, field, "get")}, |
|
|
|
|
{"getter_mut_thunk", ThunkName(ctx, field, "get_mut")}, |
|
|
|
|
{"repeated_copy_from_thunk", |
|
|
|
|
ThunkName(ctx, field, "repeated_copy_from")}, |
|
|
|
|
{"impls", |
|
|
|
|
[&] { |
|
|
|
|
ctx.Emit( |
|
|
|
|