Add Message, MessageMut, MessageView traits.

PiperOrigin-RevId: 652916543
pull/17491/head
Protobuf Team Bot 7 months ago committed by Copybara-Service
parent ac84411e4e
commit ea241fe5aa
  1. 1
      rust/BUILD
  2. 17
      rust/codegen_traits.rs
  3. 2
      rust/shared.rs
  4. 6
      src/google/protobuf/compiler/rust/message.cc

@ -47,6 +47,7 @@ rust_library(
#
# shared.rs is the root of the crate and has public items re-exported in protobuf.rs for user use.
PROTOBUF_SHARED = [
"codegen_traits.rs",
"enum.rs",
"internal.rs",
"primitive.rs",

@ -0,0 +1,17 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2024 Google LLC. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd
//! Traits that are implemeted by codegen types.
use crate::Proxied;
use std::fmt::Debug;
pub trait Message: Default + Debug + Proxied + Send + Sync {}
pub trait MessageView: Debug + Send + Sync {}
pub trait MessageMut: Debug + Sync {}

@ -22,6 +22,7 @@ use std::fmt;
/// These are the items protobuf users can access directly.
#[doc(hidden)]
pub mod __public {
pub use crate::codegen_traits::{Message, MessageMut, MessageView};
pub use crate::r#enum::{Enum, UnknownEnumValue};
pub use crate::map::{Map, MapIter, MapMut, MapView, ProxiedInMapValue};
pub use crate::optional::Optional;
@ -51,6 +52,7 @@ pub mod __runtime;
#[path = "upb.rs"]
pub mod __runtime;
mod codegen_traits;
#[path = "enum.rs"]
mod r#enum;
mod map;

@ -951,6 +951,8 @@ void GenerateRs(Context& ctx, const Descriptor& msg) {
inner: $pbr$::MessageInner
}
impl $pb$::Message for $Msg$ {}
impl std::fmt::Debug for $Msg$ {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
$Msg::debug$
@ -988,6 +990,8 @@ void GenerateRs(Context& ctx, const Descriptor& msg) {
_phantom: $Phantom$<&'msg ()>,
}
impl $pb$::MessageView for $Msg$View<'_> {}
impl std::fmt::Debug for $Msg$View<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
$Msg::debug$
@ -1047,6 +1051,8 @@ void GenerateRs(Context& ctx, const Descriptor& msg) {
inner: $pbr$::MutatorMessageRef<'msg>,
}
impl $pb$::MessageMut for $Msg$Mut<'_> {}
impl std::fmt::Debug for $Msg$Mut<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
$Msg::debug$

Loading…
Cancel
Save