From 5fe11965723ea28a06ff1bdb075f58ef3c2e79aa Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Wed, 30 Oct 2024 05:58:45 -0700 Subject: [PATCH] Adjust the protobuf prelude. Export the traits with a `Proto` prefix on them to minimize collisions (especially the high risk of confusing collision with the std prelude's AsMut). Remove Message, MessageMut and MessageView from the prelude. PiperOrigin-RevId: 691388401 --- conformance/conformance_rust.rs | 2 +- rust/prelude.rs | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/conformance/conformance_rust.rs b/conformance/conformance_rust.rs index 5b794c4a3c..820d67cff7 100644 --- a/conformance/conformance_rust.rs +++ b/conformance/conformance_rust.rs @@ -8,7 +8,7 @@ use conformance_rust_proto::{ConformanceRequest, ConformanceResponse, WireFormat use protobuf::prelude::*; use protobuf::Optional::{Set, Unset}; -use protobuf::ParseError; +use protobuf::{Message, ParseError}; use std::io::{self, ErrorKind, Read, Write}; use test_messages_edition2023_rust_proto::TestAllTypesEdition2023; diff --git a/rust/prelude.rs b/rust/prelude.rs index e06a73d252..cd98cdedb8 100644 --- a/rust/prelude.rs +++ b/rust/prelude.rs @@ -6,11 +6,18 @@ // 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. +//! +//! This module contains only the proto! macro and traits which define very +//! common fns that on messages (fns that would be methods on a base class in +//! other languages). +//! +//! All traits here have `Proto` prefixed on them, as the intent of this prelude +//! is to make the methods callable on message instances: if the traits are +//! named for generic reasons, they should be explicitly imported from the +//! `protobuf::` crate instead. pub use crate::{ - proto, AsMut, AsView, Clear, ClearAndParse, IntoMut, IntoView, MergeFrom, Message, MessageMut, - MessageView, Parse, Serialize, + proto, AsMut as ProtoAsMut, AsView as ProtoAsView, Clear as ProtoClear, + ClearAndParse as ProtoClearAndParse, IntoMut as ProtoIntoMut, IntoView as ProtoIntoView, + MergeFrom as ProtoMergeFrom, Parse as ProtoParse, Serialize as ProtoSerialize, };