Flesh out Proxied impls for $Msg$View and $Msg$Mut :: v0.6 SingularMessageField

This CL adds function bodies for: {as_view, into_view, as_mut, into_mut, set_on} [1].

Our prior cl/552609955 didn't have `RawMessage` inside $Msg$Mut, so that's also been rectified in this CL.

[1] Everything in this set is a part of the Proxied trait, except set_on, which belongs to the SettableValue trait.

PiperOrigin-RevId: 553935803
pull/13460/head
Hong Shin 2 years ago committed by Copybara-Service
parent c6810f1505
commit a81be2e610
  1. 4
      rust/test/shared/accessors_test.rs
  2. 4
      src/google/protobuf/compiler/rust/accessors/singular_message.cc
  3. 27
      src/google/protobuf/compiler/rust/message.cc

@ -229,11 +229,9 @@ fn test_optional_bytes_accessors() {
}
#[test]
#[should_panic = "b/285309454"]
#[allow(unreachable_code)]
fn test_singular_msg_field() {
let msg = TestAllTypes::new();
// TODO("b/285309454"): fetch the inner integer `bb`
// call should look like msg.optional_nested_message().bb()
match msg.optional_nested_message() {}
let _msg: unittest_proto::proto2_unittest::TestAllTypesView = msg.optional_nested_message();
}

@ -50,8 +50,8 @@ class SingularMessage final : public AccessorGenerator {
},
R"rs(
// inMsgImpl
pub fn $field$(&self) -> std::convert::Infallible {
todo!("b/285309454")
pub fn r#$field$(&self) -> $Msg$View {
$Msg$View { msg: self.msg, _phantom: std::marker::PhantomData }
}
)rs");
}

@ -301,8 +301,9 @@ void MessageGenerator::GenerateRs(Context<Descriptor> msg) {
}
#[derive(Debug, Copy, Clone)]
#[allow(dead_code)]
pub struct $Msg$View<'a> {
_msg: $pbi$::RawMessage,
msg: $pbi$::RawMessage,
_phantom: $Phantom$<&'a ()>,
}
@ -310,35 +311,43 @@ void MessageGenerator::GenerateRs(Context<Descriptor> msg) {
type Proxied = $Msg$;
fn as_view(&self) -> $pb$::View<'a, $Msg$> {
todo!("b/285309454")
*self
}
fn into_view<'shorter>(self) -> $pb$::View<'shorter, $Msg$> where 'a: 'shorter {
self
}
fn into_view<'shorter>(self) -> $pb$::View<'shorter, $Msg$> where 'a: 'shorter { todo!("b/285309454") }
}
impl<'a> $pb$::SettableValue<$Msg$> for $Msg$View<'a> {
fn set_on(self, _private: $pb$::__internal::Private, _mutator: $pb$::Mut<$Msg$>) {
todo!("b/285309454")
todo!()
}
}
#[derive(Debug)]
#[derive(Debug, Copy, Clone)]
#[allow(dead_code)]
pub struct $Msg$Mut<'a> {
msg: $pbi$::RawMessage,
_phantom: $Phantom$<&'a mut ()>,
}
unsafe impl Sync for $Msg$Mut<'_> {}
impl<'a> $pb$::MutProxy<'a> for $Msg$Mut<'a> {
fn as_mut(&mut self) -> $pb$::Mut<'_, $Msg$> {
todo!("b/285309454")
$Msg$Mut { msg: self.msg, _phantom: self._phantom }
}
fn into_mut<'shorter>(self) -> $pb$::Mut<'shorter, $Msg$> where 'a : 'shorter { todo!("b/285309454") }
fn into_mut<'shorter>(self) -> $pb$::Mut<'shorter, $Msg$> where 'a : 'shorter { self }
}
impl<'a> $pb$::ViewProxy<'a> for $Msg$Mut<'a> {
type Proxied = $Msg$;
fn as_view(&self) -> $pb$::View<'_, $Msg$> {
todo!("b/285309454")
$Msg$View { msg: self.msg, _phantom: std::marker::PhantomData }
}
fn into_view<'shorter>(self) -> $pb$::View<'shorter, $Msg$> where 'a: 'shorter {
$Msg$View { msg: self.msg, _phantom: std::marker::PhantomData }
}
fn into_view<'shorter>(self) -> $pb$::View<'shorter, $Msg$> where 'a: 'shorter { todo!("b/285309454") }
}
impl $Msg$ {

Loading…
Cancel
Save