Introduce a prelude and remove the inherent impls for serialize()
on msg, msgmut and msgview. PiperOrigin-RevId: 656007820
This commit is contained in:
Родитель
f1df391ad0
Коммит
461450834b
|
@ -7,13 +7,14 @@
|
|||
use conformance_rust_proto::{ConformanceRequest, ConformanceResponse, WireFormat};
|
||||
|
||||
#[cfg(cpp_kernel)]
|
||||
use protobuf_cpp as kernel;
|
||||
use protobuf_cpp as protobuf;
|
||||
|
||||
#[cfg(upb_kernel)]
|
||||
use protobuf_upb as kernel;
|
||||
use protobuf_upb as protobuf;
|
||||
|
||||
use kernel::Optional::{Set, Unset};
|
||||
use kernel::{Message, ParseError};
|
||||
use protobuf::prelude::*;
|
||||
use protobuf::Optional::{Set, Unset};
|
||||
use protobuf::ParseError;
|
||||
|
||||
use std::io::{self, ErrorKind, Read, Write};
|
||||
use test_messages_edition2023_rust_proto::TestAllTypesEdition2023;
|
||||
|
|
11
rust/BUILD
11
rust/BUILD
|
@ -48,18 +48,21 @@ rust_library(
|
|||
#
|
||||
# shared.rs is the root of the crate and has public items re-exported in protobuf.rs for user use.
|
||||
PROTOBUF_SHARED = [
|
||||
# go/keep-sorted start
|
||||
"codegen_traits.rs",
|
||||
"cord.rs",
|
||||
"enum.rs",
|
||||
"internal.rs",
|
||||
"primitive.rs",
|
||||
"map.rs",
|
||||
"optional.rs",
|
||||
"cord.rs",
|
||||
"prelude.rs",
|
||||
"primitive.rs",
|
||||
"proto_macro.rs",
|
||||
"proxied.rs",
|
||||
"repeated.rs",
|
||||
"shared.rs",
|
||||
"string.rs",
|
||||
"map.rs",
|
||||
"proto_macro.rs",
|
||||
# go/keep-sorted end
|
||||
]
|
||||
|
||||
# The Rust Protobuf runtime using the upb kernel.
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
// 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
|
||||
|
||||
//! Prelude for the Protobuf Rust API.
|
||||
//! This module contains only non-struct items that are needed for extremely
|
||||
//! common usages of the generated types from application code. Any struct
|
||||
//! or less common items should be imported normally.
|
||||
|
||||
pub use crate::{
|
||||
proto, AsMut, AsView, Clear, ClearAndParse, IntoMut, IntoView, Message, MessageMut,
|
||||
MessageView, Parse, Serialize,
|
||||
};
|
|
@ -21,3 +21,5 @@ use protobuf_cpp as kernel;
|
|||
use protobuf_upb as kernel;
|
||||
|
||||
pub use kernel::__public::*;
|
||||
|
||||
pub use kernel::prelude;
|
||||
|
|
|
@ -45,6 +45,8 @@ pub mod __public {
|
|||
}
|
||||
pub use __public::*;
|
||||
|
||||
pub mod prelude;
|
||||
|
||||
/// Everything in `__internal` is allowed to change without it being considered
|
||||
/// a breaking change for the protobuf library. Nothing in here should be
|
||||
/// exported in `protobuf.rs`.
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
// https://developers.google.com/open-source/licenses/bsd
|
||||
|
||||
use googletest::prelude::*;
|
||||
use protobuf_cpp::prelude::*;
|
||||
|
||||
use protobuf_cpp::__runtime::{PtrAndLen, RawMessage};
|
||||
use unittest_rust_proto::{TestAllExtensions, TestAllTypes, TestAllTypesMut, TestAllTypesView};
|
||||
|
||||
|
|
|
@ -45,7 +45,11 @@ rust_test(
|
|||
rust_test(
|
||||
name = "child_parent_upb_test",
|
||||
srcs = ["child_parent_test.rs"],
|
||||
aliases = {
|
||||
"//rust:protobuf_upb_export": "protobuf",
|
||||
},
|
||||
deps = [
|
||||
"//rust:protobuf_upb_export",
|
||||
"//rust/test:child_upb_rust_proto",
|
||||
"//rust/test:parent_upb_rust_proto",
|
||||
"@crate_index//:googletest",
|
||||
|
@ -55,7 +59,11 @@ rust_test(
|
|||
rust_test(
|
||||
name = "child_parent_cpp_test",
|
||||
srcs = ["child_parent_test.rs"],
|
||||
aliases = {
|
||||
"//rust:protobuf_cpp_export": "protobuf",
|
||||
},
|
||||
deps = [
|
||||
"//rust:protobuf_cpp_export",
|
||||
"//rust/test:child_cpp_rust_proto",
|
||||
"//rust/test:parent_cpp_rust_proto",
|
||||
"@crate_index//:googletest",
|
||||
|
@ -263,10 +271,14 @@ rust_test(
|
|||
rust_test(
|
||||
name = "serialization_upb_test",
|
||||
srcs = ["serialization_test.rs"],
|
||||
aliases = {
|
||||
"//rust:protobuf_upb_export": "protobuf",
|
||||
},
|
||||
proc_macro_deps = [
|
||||
"@crate_index//:paste",
|
||||
],
|
||||
deps = [
|
||||
"//rust:protobuf_upb_export",
|
||||
"//rust/test:unittest_edition_upb_rust_proto",
|
||||
"//rust/test:unittest_proto3_optional_upb_rust_proto",
|
||||
"//rust/test:unittest_proto3_upb_rust_proto",
|
||||
|
@ -278,10 +290,14 @@ rust_test(
|
|||
rust_test(
|
||||
name = "serialization_cpp_test",
|
||||
srcs = ["serialization_test.rs"],
|
||||
aliases = {
|
||||
"//rust:protobuf_cpp_export": "protobuf",
|
||||
},
|
||||
proc_macro_deps = [
|
||||
"@crate_index//:paste",
|
||||
],
|
||||
deps = [
|
||||
"//rust:protobuf_cpp_export",
|
||||
"//rust/test:unittest_cpp_rust_proto",
|
||||
"//rust/test:unittest_edition_cpp_rust_proto",
|
||||
"//rust/test:unittest_proto3_cpp_rust_proto",
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
// https://developers.google.com/open-source/licenses/bsd
|
||||
|
||||
use googletest::prelude::*;
|
||||
use protobuf::prelude::*;
|
||||
|
||||
#[googletest::test]
|
||||
fn test_canonical_types() {
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
// https://developers.google.com/open-source/licenses/bsd
|
||||
|
||||
use googletest::prelude::*;
|
||||
use protobuf::prelude::*;
|
||||
|
||||
use paste::paste;
|
||||
use unittest_edition_rust_proto::TestAllTypes as TestAllTypesEditions;
|
||||
use unittest_proto3_optional_rust_proto::TestProto3Optional;
|
||||
|
|
|
@ -8,13 +8,13 @@ rust_test(
|
|||
name = "utf8_cpp_test",
|
||||
srcs = ["utf8_test.rs"],
|
||||
aliases = {
|
||||
"//rust:protobuf_cpp": "protobuf",
|
||||
"//rust:protobuf_cpp_export": "protobuf",
|
||||
},
|
||||
deps = [
|
||||
":feature_verify_cpp_rust_proto",
|
||||
":no_features_proto2_cpp_rust_proto",
|
||||
":no_features_proto3_cpp_rust_proto",
|
||||
"//rust:protobuf_cpp",
|
||||
"//rust:protobuf_cpp_export",
|
||||
"@crate_index//:googletest",
|
||||
],
|
||||
)
|
||||
|
@ -23,13 +23,13 @@ rust_test(
|
|||
name = "utf8_upb_test",
|
||||
srcs = ["utf8_test.rs"],
|
||||
aliases = {
|
||||
"//rust:protobuf_upb": "protobuf",
|
||||
"//rust:protobuf_upb_export": "protobuf",
|
||||
},
|
||||
deps = [
|
||||
":feature_verify_upb_rust_proto",
|
||||
":no_features_proto2_upb_rust_proto",
|
||||
":no_features_proto3_upb_rust_proto",
|
||||
"//rust:protobuf_upb",
|
||||
"//rust:protobuf_upb_export",
|
||||
"@crate_index//:googletest",
|
||||
],
|
||||
)
|
||||
|
|
|
@ -13,8 +13,10 @@
|
|||
// behavior. Do not assume that the Protobuf team is intentional about these
|
||||
// behaviors while b/304774814 is open.
|
||||
|
||||
use feature_verify_rust_proto::Verify;
|
||||
use googletest::prelude::*;
|
||||
use protobuf::prelude::*;
|
||||
|
||||
use feature_verify_rust_proto::Verify;
|
||||
use no_features_proto2_rust_proto::NoFeaturesProto2;
|
||||
use no_features_proto3_rust_proto::NoFeaturesProto3;
|
||||
use protobuf::{ParseError, ProtoStr};
|
||||
|
|
|
@ -973,7 +973,7 @@ void GenerateRs(Context& ctx, const Descriptor& msg) {
|
|||
|
||||
impl $pb$::Serialize for $Msg$ {
|
||||
fn serialize(&self) -> Result<Vec<u8>, $pb$::SerializeError> {
|
||||
self.serialize()
|
||||
$pb$::AsView::as_view(self).serialize()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1020,7 +1020,7 @@ void GenerateRs(Context& ctx, const Descriptor& msg) {
|
|||
|
||||
impl $pb$::Serialize for $Msg$View<'_> {
|
||||
fn serialize(&self) -> Result<Vec<u8>, $pb$::SerializeError> {
|
||||
self.serialize()
|
||||
$Msg::serialize$
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1035,10 +1035,6 @@ void GenerateRs(Context& ctx, const Descriptor& msg) {
|
|||
self.msg
|
||||
}
|
||||
|
||||
pub fn serialize(&self) -> Result<Vec<u8>, $pb$::SerializeError> {
|
||||
$Msg::serialize$
|
||||
}
|
||||
|
||||
pub fn to_owned(&self) -> $Msg$ {
|
||||
$pb$::IntoProxied::into_proxied(*self, $pbi$::Private)
|
||||
}
|
||||
|
@ -1096,7 +1092,7 @@ void GenerateRs(Context& ctx, const Descriptor& msg) {
|
|||
|
||||
impl $pb$::Serialize for $Msg$Mut<'_> {
|
||||
fn serialize(&self) -> Result<Vec<u8>, $pb$::SerializeError> {
|
||||
self.serialize()
|
||||
$pb$::AsView::as_view(self).serialize()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1128,10 +1124,6 @@ void GenerateRs(Context& ctx, const Descriptor& msg) {
|
|||
self.inner
|
||||
}
|
||||
|
||||
pub fn serialize(&self) -> Result<Vec<u8>, $pb$::SerializeError> {
|
||||
$pb$::AsView::as_view(self).serialize()
|
||||
}
|
||||
|
||||
pub fn to_owned(&self) -> $Msg$ {
|
||||
$pb$::AsView::as_view(self).to_owned()
|
||||
}
|
||||
|
@ -1200,9 +1192,6 @@ void GenerateRs(Context& ctx, const Descriptor& msg) {
|
|||
|
||||
$raw_arena_getter_for_message$
|
||||
|
||||
pub fn serialize(&self) -> Result<Vec<u8>, $pb$::SerializeError> {
|
||||
self.as_view().serialize()
|
||||
}
|
||||
#[deprecated = "Prefer Msg::parse(), or use the new name 'clear_and_parse' to parse into a pre-existing message."]
|
||||
pub fn deserialize(&mut self, data: &[u8]) -> Result<(), $pb$::ParseError> {
|
||||
self.clear_and_parse(data)
|
||||
|
|
Загрузка…
Ссылка в новой задаче