From 3c95fc8b762d96a18effb508b46cee1e4d8c2946 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Tue, 23 Jul 2024 07:54:29 -0700 Subject: [PATCH] Create AsView/IntoView/AsMut/IntoMut traits These 'verb' traits are more in line with our plans for the common message operations. PiperOrigin-RevId: 655163895 --- rust/codegen_traits.rs | 2 +- rust/map.rs | 35 +++-- rust/primitive.rs | 21 ++- rust/proxied.rs | 131 ++++++++++++------- rust/repeated.rs | 42 ++++-- rust/shared.rs | 3 +- rust/string.rs | 17 ++- rust/test/shared/accessors_repeated_test.rs | 2 +- src/google/protobuf/compiler/rust/enum.cc | 11 +- src/google/protobuf/compiler/rust/message.cc | 55 +++++--- 10 files changed, 216 insertions(+), 103 deletions(-) diff --git a/rust/codegen_traits.rs b/rust/codegen_traits.rs index fe5de9916b..c48c5c02a1 100644 --- a/rust/codegen_traits.rs +++ b/rust/codegen_traits.rs @@ -43,7 +43,7 @@ pub trait MessageView<'msg>: ViewProxy<'msg, Proxied = Self::Message> /// A trait that all generated message muts implement. pub trait MessageMut<'msg>: - MutProxy<'msg, Proxied = Self::Message> + MutProxy<'msg, MutProxied = Self::Message> // Read traits: + Debug + Serialize // Write traits: diff --git a/rust/map.rs b/rust/map.rs index 0e7953f872..7013226ec7 100644 --- a/rust/map.rs +++ b/rust/map.rs @@ -6,7 +6,8 @@ // https://developers.google.com/open-source/licenses/bsd use crate::{ - IntoProxied, Mut, MutProxied, MutProxy, Proxied, Proxy, View, ViewProxy, + AsMut, AsView, IntoMut, IntoProxied, IntoView, Mut, MutProxied, MutProxy, Proxied, Proxy, View, + ViewProxy, __internal::Private, __runtime::{InnerMap, InnerMapMut, RawMap, RawMapIter}, }; @@ -112,14 +113,18 @@ impl> MutProxied for Map { type Mut<'msg> = MapMut<'msg, K, V> where K: 'msg, V: 'msg; } -impl<'msg, K: Proxied, V: ProxiedInMapValue> Proxy<'msg> for MapView<'msg, K, V> { +impl<'msg, K: Proxied, V: ProxiedInMapValue> Proxy<'msg> for MapView<'msg, K, V> {} + +impl<'msg, K: Proxied, V: ProxiedInMapValue> AsView for MapView<'msg, K, V> { type Proxied = Map; - fn as_view(&self) -> View<'_, Self::Proxied> { + fn as_view(&self) -> MapView<'_, K, V> { *self } +} - fn into_view<'shorter>(self) -> View<'shorter, Self::Proxied> +impl<'msg, K: Proxied, V: ProxiedInMapValue> IntoView<'msg> for MapView<'msg, K, V> { + fn into_view<'shorter>(self) -> MapView<'shorter, K, V> where 'msg: 'shorter, { @@ -129,14 +134,18 @@ impl<'msg, K: Proxied, V: ProxiedInMapValue> Proxy<'msg> for MapView<'msg, K, impl<'msg, K: Proxied, V: ProxiedInMapValue> ViewProxy<'msg> for MapView<'msg, K, V> {} -impl<'msg, K: Proxied, V: ProxiedInMapValue> Proxy<'msg> for MapMut<'msg, K, V> { +impl<'msg, K: Proxied, V: ProxiedInMapValue> Proxy<'msg> for MapMut<'msg, K, V> {} + +impl<'msg, K: Proxied, V: ProxiedInMapValue> AsView for MapMut<'msg, K, V> { type Proxied = Map; - fn as_view(&self) -> View<'_, Self::Proxied> { + fn as_view(&self) -> MapView<'_, K, V> { MapView { raw: self.inner.raw, _phantom: PhantomData } } +} - fn into_view<'shorter>(self) -> View<'shorter, Self::Proxied> +impl<'msg, K: Proxied, V: ProxiedInMapValue> IntoView<'msg> for MapMut<'msg, K, V> { + fn into_view<'shorter>(self) -> MapView<'shorter, K, V> where 'msg: 'shorter, { @@ -144,12 +153,16 @@ impl<'msg, K: Proxied, V: ProxiedInMapValue> Proxy<'msg> for MapMut<'msg, K, } } -impl<'msg, K: Proxied, V: ProxiedInMapValue> MutProxy<'msg> for MapMut<'msg, K, V> { - fn as_mut(&mut self) -> Mut<'_, Self::Proxied> { +impl<'msg, K: Proxied, V: ProxiedInMapValue> AsMut for MapMut<'msg, K, V> { + type MutProxied = Map; + + fn as_mut(&mut self) -> MapMut<'_, K, V> { MapMut { inner: self.inner, _phantom: PhantomData } } +} - fn into_mut<'shorter>(self) -> Mut<'shorter, Self::Proxied> +impl<'msg, K: Proxied, V: ProxiedInMapValue> IntoMut<'msg> for MapMut<'msg, K, V> { + fn into_mut<'shorter>(self) -> MapMut<'shorter, K, V> where 'msg: 'shorter, { @@ -157,6 +170,8 @@ impl<'msg, K: Proxied, V: ProxiedInMapValue> MutProxy<'msg> for MapMut<'msg, } } +impl<'msg, K: Proxied, V: ProxiedInMapValue> MutProxy<'msg> for MapMut<'msg, K, V> {} + impl Map where K: Proxied, diff --git a/rust/primitive.rs b/rust/primitive.rs index ab50352f14..06c90f1536 100644 --- a/rust/primitive.rs +++ b/rust/primitive.rs @@ -5,7 +5,7 @@ // license that can be found in the LICENSE file or at // https://developers.google.com/open-source/licenses/bsd use crate::__internal::Private; -use crate::{IntoProxied, Proxied, Proxy, View, ViewProxy}; +use crate::{AsView, IntoProxied, IntoView, Proxied, Proxy, ViewProxy}; macro_rules! impl_singular_primitives { ($($t:ty),*) => { @@ -15,15 +15,22 @@ macro_rules! impl_singular_primitives { } impl<'msg> Proxy<'msg> for $t { + } + + impl AsView for $t { type Proxied = $t; - fn as_view(&self) -> View<'_, Self::Proxied> { - *self - } + fn as_view(&self) -> $t { + *self + } + } - fn into_view<'shorter>(self) -> View<'shorter, Self::Proxied> { - self - } + impl<'msg> IntoView<'msg> for $t { + fn into_view<'shorter>(self) -> $t + where + 'msg: 'shorter { + self + } } impl<'msg> ViewProxy<'msg> for $t {} diff --git a/rust/proxied.rs b/rust/proxied.rs index f252b2e879..3092109566 100644 --- a/rust/proxied.rs +++ b/rust/proxied.rs @@ -72,7 +72,7 @@ pub trait MutProxied: Proxied { /// `&'msg mut T`. /// /// Most code should use the type alias [`Mut`]. - type Mut<'msg>: MutProxy<'msg, Proxied = Self> + type Mut<'msg>: MutProxy<'msg, MutProxied = Self> where Self: 'msg; } @@ -90,13 +90,13 @@ pub type View<'msg, T> = ::View<'msg>; #[allow(dead_code)] pub type Mut<'msg, T> = ::Mut<'msg>; -/// Declares conversion operations common to all proxies (both views and mut -/// proxies). +/// Used to semantically do a cheap "to-reference" conversion. This is +/// implemented on both owned `Proxied` types as well as ViewProxy and MutProxy +/// types. /// -/// This trait is intentionally made non-object-safe to prevent a potential -/// future incompatible change. -pub trait Proxy<'msg>: 'msg + Sync + Unpin + Sized + Debug { - type Proxied: 'msg + Proxied; +/// On ViewProxy this will behave as a reborrow into a shorter lifetime. +pub trait AsView { + type Proxied: Proxied; /// Converts a borrow into a `View` with the lifetime of that borrow. /// @@ -118,7 +118,16 @@ pub trait Proxy<'msg>: 'msg + Sync + Unpin + Sized + Debug { /// /// [invariant]: https://doc.rust-lang.org/nomicon/subtyping.html#variance fn as_view(&self) -> View<'_, Self::Proxied>; +} +/// Used to turn another 'borrow' into a ViewProxy. +/// +/// On a MutProxy this borrows to a View (semantically matching turning a `&mut +/// T` into a `&T`). +/// +/// On a ViewProxy this will behave as a reborrow into a shorter lifetime +/// (semantically matching a `&'a T` into a `&'b T` where `'a: 'b`). +pub trait IntoView<'msg>: AsView { /// Converts into a `View` with a potentially shorter lifetime. /// /// In non-generic code we don't need to use `into_view` because the proxy @@ -149,41 +158,22 @@ pub trait Proxy<'msg>: 'msg + Sync + Unpin + Sized + Debug { 'msg: 'shorter; } -/// Declares conversion operations common to view proxies. -pub trait ViewProxy<'msg>: Proxy<'msg> + Copy + Send {} - -/// Declares operations common to all mut proxies. +/// Used to semantically do a cheap "to-mut-reference" conversion. This is +/// implemented on both owned `Proxied` types as well as MutProxy types. /// -/// This trait is intentionally made non-object-safe to prevent a potential -/// future incompatible change. -pub trait MutProxy<'msg>: Proxy<'msg> -where - Self::Proxied: MutProxied, -{ - /// Gets an immutable view of this field. This is shorthand for `as_view`. - /// - /// This provides a shorter lifetime than `into_view` but can also be called - /// multiple times - if the result of `get` is not living long enough - /// for your use, use that instead. - fn get(&self) -> View<'_, Self::Proxied> { - self.as_view() - } +/// On MutProxy this will behave as a reborrow into a shorter lifetime. +pub trait AsMut: AsView { + type MutProxied: MutProxied; /// Converts a borrow into a `Mut` with the lifetime of that borrow. - /// - /// This function enables calling multiple methods consuming `self`, for - /// example: - /// - /// ```ignore - /// let mut sub: Mut = msg.submsg_mut(); - /// sub.as_mut().field_x_mut().set(10); // field_x_mut is fn(self) - /// sub.field_y_mut().set(20); // `sub` is now consumed - /// ``` - /// - /// `as_mut` is also useful in generic code to explicitly perform the - /// operation that in concrete code coercion would perform implicitly. - fn as_mut(&mut self) -> Mut<'_, Self::Proxied>; + fn as_mut(&mut self) -> Mut<'_, Self::MutProxied>; +} +/// Used to turn another 'borrow' into a MutProxy. +/// +/// On a MutProxy this will behave as a reborrow into a shorter lifetime +/// (semantically matching a `&mut 'a T` into a `&mut 'b T` where `'a: 'b`). +pub trait IntoMut<'msg>: AsMut { /// Converts into a `Mut` with a potentially shorter lifetime. /// /// In non-generic code we don't need to use `into_mut` because the proxy @@ -206,11 +196,36 @@ where /// ``` /// /// [invariant]: https://doc.rust-lang.org/nomicon/subtyping.html#variance - fn into_mut<'shorter>(self) -> Mut<'shorter, Self::Proxied> + fn into_mut<'shorter>(self) -> Mut<'shorter, Self::MutProxied> where 'msg: 'shorter; } +/// Declares conversion operations common to all proxies (both views and mut +/// proxies). +/// +/// This trait is intentionally made non-object-safe to prevent a potential +/// future incompatible change. +pub trait Proxy<'msg>: 'msg + IntoView<'msg> + Sync + Unpin + Sized + Debug {} + +/// Declares conversion operations common to view proxies. +pub trait ViewProxy<'msg>: Proxy<'msg> + Copy + Send {} + +/// Declares operations common to all mut proxies. +/// +/// This trait is intentionally made non-object-safe to prevent a potential +/// future incompatible change. +pub trait MutProxy<'msg>: Proxy<'msg> + AsMut + IntoMut<'msg> { + /// Gets an immutable view of this field. This is shorthand for `as_view`. + /// + /// This provides a shorter lifetime than `into_view` but can also be called + /// multiple times - if the result of `get` is not living long enough + /// for your use, use that instead. + fn get(&self) -> View<'_, Self::Proxied> { + self.as_view() + } +} + /// A value to `Proxied`-value conversion that consumes the input value. /// /// All setter functions accept types that implement `IntoProxied`. The purpose @@ -263,14 +278,20 @@ mod tests { } } - impl<'msg> Proxy<'msg> for MyProxiedView<'msg> { + impl<'msg> Proxy<'msg> for MyProxiedView<'msg> {} + + impl<'msg> ViewProxy<'msg> for MyProxiedView<'msg> {} + + impl<'msg> AsView for MyProxiedView<'msg> { type Proxied = MyProxied; - fn as_view(&self) -> View<'msg, MyProxied> { + fn as_view(&self) -> MyProxiedView<'msg> { *self } + } - fn into_view<'shorter>(self) -> View<'shorter, MyProxied> + impl<'msg> IntoView<'msg> for MyProxiedView<'msg> { + fn into_view<'shorter>(self) -> MyProxiedView<'shorter> where 'msg: 'shorter, { @@ -278,19 +299,22 @@ mod tests { } } - impl<'msg> ViewProxy<'msg> for MyProxiedView<'msg> {} - #[derive(Debug)] struct MyProxiedMut<'msg> { my_proxied_ref: &'msg mut MyProxied, } - impl<'msg> Proxy<'msg> for MyProxiedMut<'msg> { + impl<'msg> Proxy<'msg> for MyProxiedMut<'msg> {} + + impl<'msg> AsView for MyProxiedMut<'msg> { type Proxied = MyProxied; - fn as_view(&self) -> View<'_, MyProxied> { + fn as_view(&self) -> MyProxiedView<'_> { MyProxiedView { my_proxied_ref: self.my_proxied_ref } } + } + + impl<'msg> IntoView<'msg> for MyProxiedMut<'msg> { fn into_view<'shorter>(self) -> View<'shorter, MyProxied> where 'msg: 'shorter, @@ -299,12 +323,16 @@ mod tests { } } - impl<'msg> MutProxy<'msg> for MyProxiedMut<'msg> { - fn as_mut(&mut self) -> Mut<'_, MyProxied> { + impl<'msg> AsMut for MyProxiedMut<'msg> { + type MutProxied = MyProxied; + + fn as_mut(&mut self) -> MyProxiedMut<'_> { MyProxiedMut { my_proxied_ref: self.my_proxied_ref } } + } - fn into_mut<'shorter>(self) -> Mut<'shorter, MyProxied> + impl<'msg> IntoMut<'msg> for MyProxiedMut<'msg> { + fn into_mut<'shorter>(self) -> MyProxiedMut<'shorter> where 'msg: 'shorter, { @@ -312,6 +340,8 @@ mod tests { } } + impl<'msg> MutProxy<'msg> for MyProxiedMut<'msg> {} + #[googletest::test] fn test_as_view() { let my_proxied = MyProxied { val: "Hello World".to_string() }; @@ -427,7 +457,8 @@ mod tests { // `[x, y]` fails to compile because `'a` is not the same as `'b` and the `Mut` // lifetime parameter is (conservatively) invariant. // `[x.as_mut(), y]` fails because that borrow cannot outlive `'b`. - [x.into_mut(), y] + let tmp: Mut<'b, T> = x.into_mut(); + [tmp, y] } #[googletest::test] diff --git a/rust/repeated.rs b/rust/repeated.rs index d7a02e4c5d..0db3f64a96 100644 --- a/rust/repeated.rs +++ b/rust/repeated.rs @@ -15,7 +15,8 @@ use std::iter::FusedIterator; use std::marker::PhantomData; use crate::{ - IntoProxied, Mut, MutProxied, MutProxy, Proxied, Proxy, View, ViewProxy, + AsMut, AsView, IntoMut, IntoProxied, IntoView, Mut, MutProxied, MutProxy, Proxied, Proxy, View, + ViewProxy, __internal::Private, __runtime::{InnerRepeated, InnerRepeatedMut, RawRepeatedField}, }; @@ -397,17 +398,24 @@ where type Mut<'msg> = RepeatedMut<'msg, T> where Repeated: 'msg; } -impl<'msg, T> Proxy<'msg> for RepeatedView<'msg, T> +impl<'msg, T> Proxy<'msg> for RepeatedView<'msg, T> where T: ProxiedInRepeated + 'msg {} + +impl<'msg, T> AsView for RepeatedView<'msg, T> where T: ProxiedInRepeated + 'msg, { type Proxied = Repeated; #[inline] - fn as_view(&self) -> View<'_, Self::Proxied> { + fn as_view(&self) -> View<'msg, Self::Proxied> { *self } +} +impl<'msg, T> IntoView<'msg> for RepeatedView<'msg, T> +where + T: ProxiedInRepeated + 'msg, +{ #[inline] fn into_view<'shorter>(self) -> View<'shorter, Self::Proxied> where @@ -419,19 +427,26 @@ where impl<'msg, T> ViewProxy<'msg> for RepeatedView<'msg, T> where T: ProxiedInRepeated + 'msg {} -impl<'msg, T> Proxy<'msg> for RepeatedMut<'msg, T> +impl<'msg, T> Proxy<'msg> for RepeatedMut<'msg, T> where T: ProxiedInRepeated + 'msg {} + +impl<'msg, T> AsView for RepeatedMut<'msg, T> where T: ProxiedInRepeated + 'msg, { type Proxied = Repeated; #[inline] - fn as_view(&self) -> View<'_, Self::Proxied> { + fn as_view(&self) -> RepeatedView<'_, T> { RepeatedView { raw: self.inner.raw, _phantom: PhantomData } } +} +impl<'msg, T> IntoView<'msg> for RepeatedMut<'msg, T> +where + T: ProxiedInRepeated + 'msg, +{ #[inline] - fn into_view<'shorter>(self) -> View<'shorter, Self::Proxied> + fn into_view<'shorter>(self) -> RepeatedView<'shorter, T> where 'msg: 'shorter, { @@ -439,17 +454,24 @@ where } } -impl<'msg, T> MutProxy<'msg> for RepeatedMut<'msg, T> +impl<'msg, T> AsMut for RepeatedMut<'msg, T> where T: ProxiedInRepeated + 'msg, { + type MutProxied = Repeated; + #[inline] - fn as_mut(&mut self) -> Mut<'_, Self::Proxied> { + fn as_mut(&mut self) -> RepeatedMut<'_, T> { RepeatedMut { inner: self.inner, _phantom: PhantomData } } +} +impl<'msg, T> IntoMut<'msg> for RepeatedMut<'msg, T> +where + T: ProxiedInRepeated + 'msg, +{ #[inline] - fn into_mut<'shorter>(self) -> Mut<'shorter, Self::Proxied> + fn into_mut<'shorter>(self) -> RepeatedMut<'shorter, T> where 'msg: 'shorter, { @@ -457,6 +479,8 @@ where } } +impl<'msg, T> MutProxy<'msg> for RepeatedMut<'msg, T> where T: ProxiedInRepeated + 'msg {} + impl<'msg, T> iter::Iterator for RepeatedIter<'msg, T> where T: ProxiedInRepeated + 'msg, diff --git a/rust/shared.rs b/rust/shared.rs index 113292c875..716f34262f 100644 --- a/rust/shared.rs +++ b/rust/shared.rs @@ -33,7 +33,8 @@ pub mod __public { pub use crate::optional::Optional; pub use crate::proto; pub use crate::proxied::{ - IntoProxied, Mut, MutProxied, MutProxy, Proxied, Proxy, View, ViewProxy, + AsMut, AsView, IntoMut, IntoProxied, IntoView, Mut, MutProxied, MutProxy, Proxied, Proxy, + View, ViewProxy, }; pub use crate::repeated::{ ProxiedInRepeated, Repeated, RepeatedIter, RepeatedMut, RepeatedView, diff --git a/rust/string.rs b/rust/string.rs index e3b8365b40..3a90ba3db8 100644 --- a/rust/string.rs +++ b/rust/string.rs @@ -11,7 +11,10 @@ use crate::__internal::Private; use crate::__runtime::{InnerProtoString, PtrAndLen, RawMessage}; -use crate::{IntoProxied, Mut, MutProxied, MutProxy, Optional, Proxied, Proxy, View, ViewProxy}; +use crate::{ + AsView, IntoProxied, IntoView, Mut, MutProxied, MutProxy, Optional, Proxied, Proxy, View, + ViewProxy, +}; use std::borrow::Cow; use std::cmp::{Eq, Ord, Ordering, PartialEq, PartialOrd}; use std::convert::{AsMut, AsRef}; @@ -114,13 +117,17 @@ impl IntoProxied for Arc<[u8]> { } } -impl<'msg> Proxy<'msg> for &'msg [u8] { +impl<'msg> Proxy<'msg> for &'msg [u8] {} + +impl AsView for &[u8] { type Proxied = ProtoBytes; fn as_view(&self) -> &[u8] { self } +} +impl<'msg> IntoView<'msg> for &'msg [u8] { fn into_view<'shorter>(self) -> &'shorter [u8] where 'msg: 'shorter, @@ -481,13 +488,17 @@ impl Proxied for ProtoString { type View<'msg> = &'msg ProtoStr; } -impl<'msg> Proxy<'msg> for &'msg ProtoStr { +impl<'msg> Proxy<'msg> for &'msg ProtoStr {} + +impl AsView for &ProtoStr { type Proxied = ProtoString; fn as_view(&self) -> &ProtoStr { self } +} +impl<'msg> IntoView<'msg> for &'msg ProtoStr { fn into_view<'shorter>(self) -> &'shorter ProtoStr where 'msg: 'shorter, diff --git a/rust/test/shared/accessors_repeated_test.rs b/rust/test/shared/accessors_repeated_test.rs index 8898d9c096..c1de003561 100644 --- a/rust/test/shared/accessors_repeated_test.rs +++ b/rust/test/shared/accessors_repeated_test.rs @@ -7,7 +7,7 @@ use googletest::prelude::*; use paste::paste; -use protobuf::Proxy; +use protobuf::AsView; use unittest_rust_proto::{test_all_types, test_all_types::NestedMessage, TestAllTypes}; macro_rules! generate_repeated_numeric_test { diff --git a/src/google/protobuf/compiler/rust/enum.cc b/src/google/protobuf/compiler/rust/enum.cc index a2b1143146..9513c93eb2 100644 --- a/src/google/protobuf/compiler/rust/enum.cc +++ b/src/google/protobuf/compiler/rust/enum.cc @@ -405,20 +405,23 @@ void GenerateEnumDefinition(Context& ctx, const EnumDescriptor& desc) { type View<'a> = $name$; } - impl $pb$::Proxy<'_> for $name$ { + impl $pb$::Proxy<'_> for $name$ {} + impl $pb$::ViewProxy<'_> for $name$ {} + + impl $pb$::AsView for $name$ { type Proxied = $name$; fn as_view(&self) -> $name$ { *self } + } - fn into_view<'shorter>(self) -> $pb$::View<'shorter, $name$> { + impl<'msg> $pb$::IntoView<'msg> for $name$ { + fn into_view<'shorter>(self) -> $name$ where 'msg: 'shorter { self } } - impl $pb$::ViewProxy<'_> for $name$ {} - unsafe impl $pb$::ProxiedInRepeated for $name$ { fn repeated_new(_private: $pbi$::Private) -> $pb$::Repeated { $pbr$::new_enum_repeated($pbi$::Private) diff --git a/src/google/protobuf/compiler/rust/message.cc b/src/google/protobuf/compiler/rust/message.cc index d8b354d6ac..b0a16df41c 100644 --- a/src/google/protobuf/compiler/rust/message.cc +++ b/src/google/protobuf/compiler/rust/message.cc @@ -260,7 +260,7 @@ void IntoProxiedForMessage(Context& ctx, const Descriptor& msg) { impl<'msg> $pb$::IntoProxied<$Msg$> for $Msg$Mut<'msg> { fn into_proxied(self, _private: $pbi$::Private) -> $Msg$ { - $pb$::IntoProxied::into_proxied($pb$::Proxy::into_view(self), _private) + $pb$::IntoProxied::into_proxied($pb$::IntoView::into_view(self), _private) } } @@ -289,7 +289,7 @@ void IntoProxiedForMessage(Context& ctx, const Descriptor& msg) { impl<'msg> $pb$::IntoProxied<$Msg$> for $Msg$Mut<'msg> { fn into_proxied(self, _private: $pbi$::Private) -> $Msg$ { - $pb$::IntoProxied::into_proxied($pb$::Proxy::into_view(self), _private) + $pb$::IntoProxied::into_proxied($pb$::IntoView::into_view(self), _private) } } @@ -1055,19 +1055,24 @@ void GenerateRs(Context& ctx, const Descriptor& msg) { // - `$Msg$View` does not use thread-local data. unsafe impl Send for $Msg$View<'_> {} - impl<'msg> $pb$::Proxy<'msg> for $Msg$View<'msg> { - type Proxied = $Msg$; + impl<'msg> $pb$::Proxy<'msg> for $Msg$View<'msg> {} + impl<'msg> $pb$::ViewProxy<'msg> for $Msg$View<'msg> {} + impl<'msg> $pb$::AsView for $Msg$View<'msg> { + type Proxied = $Msg$; fn as_view(&self) -> $pb$::View<'msg, $Msg$> { *self } - fn into_view<'shorter>(self) -> $pb$::View<'shorter, $Msg$> where 'msg: 'shorter { + } + + impl<'msg> $pb$::IntoView<'msg> for $Msg$View<'msg> { + fn into_view<'shorter>(self) -> $Msg$View<'shorter> + where + 'msg: 'shorter { self } } - impl<'msg> $pb$::ViewProxy<'msg> for $Msg$View<'msg> {} - $into_proxied_impl$ $repeated_impl$ @@ -1124,11 +1129,11 @@ void GenerateRs(Context& ctx, const Descriptor& msg) { } pub fn serialize(&self) -> Result, $pb$::SerializeError> { - $pb$::Proxy::as_view(self).serialize() + $pb$::AsView::as_view(self).serialize() } pub fn to_owned(&self) -> $Msg$ { - $pb$::Proxy::as_view(self).to_owned() + $pb$::AsView::as_view(self).to_owned() } $msg_merge_from$ @@ -1146,23 +1151,39 @@ void GenerateRs(Context& ctx, const Descriptor& msg) { // splitting, synchronous access of an arena is impossible. unsafe impl Sync for $Msg$Mut<'_> {} - impl<'msg> $pb$::MutProxy<'msg> for $Msg$Mut<'msg> { - fn as_mut(&mut self) -> $pb$::Mut<'_, $Msg$> { - $Msg$Mut { inner: self.inner } - } - fn into_mut<'shorter>(self) -> $pb$::Mut<'shorter, $Msg$> where 'msg : 'shorter { self } - } + impl<'msg> $pb$::Proxy<'msg> for $Msg$Mut<'msg> {} + impl<'msg> $pb$::MutProxy<'msg> for $Msg$Mut<'msg> {} - impl<'msg> $pb$::Proxy<'msg> for $Msg$Mut<'msg> { + impl<'msg> $pb$::AsView for $Msg$Mut<'msg> { type Proxied = $Msg$; fn as_view(&self) -> $pb$::View<'_, $Msg$> { $Msg$View { msg: self.raw_msg(), _phantom: $std$::marker::PhantomData } } - fn into_view<'shorter>(self) -> $pb$::View<'shorter, $Msg$> where 'msg: 'shorter { + } + + impl<'msg> $pb$::IntoView<'msg> for $Msg$Mut<'msg> { + fn into_view<'shorter>(self) -> $pb$::View<'shorter, $Msg$> + where + 'msg: 'shorter { $Msg$View { msg: self.raw_msg(), _phantom: $std$::marker::PhantomData } } } + impl<'msg> $pb$::AsMut for $Msg$Mut<'msg> { + type MutProxied = $Msg$; + fn as_mut(&mut self) -> $Msg$Mut<'msg> { + $Msg$Mut { inner: self.inner } + } + } + + impl<'msg> $pb$::IntoMut<'msg> for $Msg$Mut<'msg> { + fn into_mut<'shorter>(self) -> $Msg$Mut<'shorter> + where + 'msg: 'shorter { + self + } + } + #[allow(dead_code)] impl $Msg$ { pub fn new() -> Self {