Add AsView and AsMut implementations to owned messages.

Add subtraits to ensure:
- All Messages impl AsView + AsMut
- All ViewProxies impl AsView
- All MutProxies impl AsView + AsMut

PiperOrigin-RevId: 655585740
pull/17582/head
Protobuf Team Bot 6 months ago committed by Copybara-Service
parent 9f0fc68b38
commit e618b282d4
  1. 15
      rust/codegen_traits.rs
  2. 14
      src/google/protobuf/compiler/rust/message.cc

@ -7,7 +7,7 @@
//! Traits that are implemeted by codegen types.
use crate::{MutProxied, MutProxy, ViewProxy};
use crate::{AsMut, AsView, MutProxied, MutProxy, ViewProxy};
use create::Parse;
use read::Serialize;
use std::fmt::Debug;
@ -18,10 +18,10 @@ pub trait Message: MutProxied
// Create traits:
+ create::Parse + Default
// Read traits:
+ Debug + Serialize
+ Debug + Serialize + AsView
// Write traits:
// TODO: Msg should impl Clear.
+ ClearAndParse
+ ClearAndParse + AsMut
// Thread safety:
+ Send + Sync
// Copy/Clone:
@ -31,11 +31,11 @@ pub trait Message: MutProxied
/// A trait that all generated message views implement.
pub trait MessageView<'msg>: ViewProxy<'msg, Proxied = Self::Message>
// Read traits:
+ Debug + Serialize
+ Debug + Serialize + AsView
// Thread safety:
+ Send + Sync
// Copy/Clone:
+ Copy + Clone
// Copy/Clone:
+ Copy + Clone
{
#[doc(hidden)]
type Message: Message;
@ -45,8 +45,9 @@ pub trait MessageView<'msg>: ViewProxy<'msg, Proxied = Self::Message>
pub trait MessageMut<'msg>:
MutProxy<'msg, MutProxied = Self::Message>
// Read traits:
+ Debug + Serialize
+ Debug + Serialize + AsView
// Write traits:
+ AsMut
// TODO: MsgMut should impl Clear and ClearAndParse.
// Thread safety:
+ Sync

@ -1246,6 +1246,20 @@ void GenerateRs(Context& ctx, const Descriptor& msg) {
}
}
impl $pb$::AsView for $Msg$ {
type Proxied = Self;
fn as_view(&self) -> $Msg$View {
self.as_view()
}
}
impl $pb$::AsMut for $Msg$ {
type MutProxied = Self;
fn as_mut(&mut self) -> $Msg$Mut {
self.as_mut()
}
}
extern "C" {
$Msg_externs$

Loading…
Cancel
Save