diff --git a/rust/cpp.rs b/rust/cpp.rs index 2b5359c04..d9738384a 100644 --- a/rust/cpp.rs +++ b/rust/cpp.rs @@ -10,7 +10,7 @@ use crate::__internal::{Enum, Private}; use crate::{ IntoProxied, Map, MapIter, Mut, ProtoBytes, ProtoStr, ProtoString, Proxied, ProxiedInMapValue, - ProxiedInRepeated, Repeated, RepeatedMut, RepeatedView, View, + ProxiedInRepeated, Repeated, RepeatedMut, RepeatedView, View, MapMut, MapView, }; use paste::paste; use std::fmt; @@ -906,21 +906,21 @@ macro_rules! impl_ProxiedInMapValue_for_non_generated_value_types { } - fn map_clear(mut map: Mut<'_, Map<$key_t, Self>>) { + fn map_clear(mut map: MapMut<$key_t, Self>) { unsafe { [< proto2_rust_thunk_Map_ $key_t _ $t _clear >](map.as_raw(Private)); } } - fn map_len(map: View<'_, Map<$key_t, Self>>) -> usize { + fn map_len(map: MapView<$key_t, Self>) -> usize { unsafe { [< proto2_rust_thunk_Map_ $key_t _ $t _size >](map.as_raw(Private)) } } - fn map_insert(mut map: Mut<'_, Map<$key_t, Self>>, key: View<'_, $key_t>, value: impl IntoProxied) -> bool { + fn map_insert(mut map: MapMut<$key_t, Self>, key: View<'_, $key_t>, value: impl IntoProxied) -> bool { let ffi_key = $to_ffi_key(key); let ffi_value = $to_ffi_value(value.into_proxied(Private)); unsafe { [< proto2_rust_thunk_Map_ $key_t _ $t _insert >](map.as_raw(Private), ffi_key, ffi_value) } } - fn map_get<'a>(map: View<'a, Map<$key_t, Self>>, key: View<'_, $key_t>) -> Option> { + fn map_get<'a>(map: MapView<'a, $key_t, Self>, key: View<'_, $key_t>) -> Option> { let ffi_key = $to_ffi_key(key); let mut ffi_value = MaybeUninit::uninit(); let found = unsafe { [< proto2_rust_thunk_Map_ $key_t _ $t _get >](map.as_raw(Private), ffi_key, ffi_value.as_mut_ptr()) }; @@ -932,13 +932,13 @@ macro_rules! impl_ProxiedInMapValue_for_non_generated_value_types { Some($from_ffi_value(unsafe { ffi_value.assume_init() })) } - fn map_remove(mut map: Mut<'_, Map<$key_t, Self>>, key: View<'_, $key_t>) -> bool { + fn map_remove(mut map: MapMut<$key_t, Self>, key: View<'_, $key_t>) -> bool { let ffi_key = $to_ffi_key(key); let mut ffi_value = MaybeUninit::uninit(); unsafe { [< proto2_rust_thunk_Map_ $key_t _ $t _remove >](map.as_raw(Private), ffi_key, ffi_value.as_mut_ptr()) } } - fn map_iter(map: View<'_, Map<$key_t, Self>>) -> MapIter<'_, $key_t, Self> { + fn map_iter(map: MapView<$key_t, Self>) -> MapIter<$key_t, Self> { // SAFETY: // - The backing map for `map.as_raw` is valid for at least '_. // - A View that is live for '_ guarantees the backing map is unmodified for '_. diff --git a/rust/map.rs b/rust/map.rs index ee0f87ef8..6dfa88236 100644 --- a/rust/map.rs +++ b/rust/map.rs @@ -6,7 +6,7 @@ // https://developers.google.com/open-source/licenses/bsd use crate::{ - AsMut, AsView, IntoMut, IntoProxied, IntoView, Mut, MutProxied, MutProxy, Proxied, Proxy, View, + AsMut, AsView, IntoMut, IntoProxied, IntoView, MutProxied, MutProxy, Proxied, Proxy, View, ViewProxy, __internal::{Private, SealedInternal}, __runtime::{InnerMap, InnerMapMut, RawMap, RawMapIter}, @@ -93,17 +93,13 @@ where /// - After `map_free`, no other methods on the input are safe to call. unsafe fn map_free(_private: Private, map: &mut Map); - fn map_clear(map: Mut<'_, Map>); - fn map_len(map: View<'_, Map>) -> usize; - fn map_insert( - map: Mut<'_, Map>, - key: View<'_, K>, - value: impl IntoProxied, - ) -> bool; - fn map_get<'a>(map: View<'a, Map>, key: View<'_, K>) -> Option>; - fn map_remove(map: Mut<'_, Map>, key: View<'_, K>) -> bool; + fn map_clear(map: MapMut); + fn map_len(map: MapView) -> usize; + fn map_insert(map: MapMut, key: View<'_, K>, value: impl IntoProxied) -> bool; + fn map_get<'a>(map: MapView<'a, K, Self>, key: View<'_, K>) -> Option>; + fn map_remove(map: MapMut, key: View<'_, K>) -> bool; - fn map_iter(map: View<'_, Map>) -> MapIter<'_, K, Self>; + fn map_iter(map: MapView) -> MapIter; fn map_iter_next<'a>(iter: &mut MapIter<'a, K, Self>) -> Option<(View<'a, K>, View<'a, Self>)>; } @@ -361,7 +357,7 @@ where /// Returns an iterator visiting all key-value pairs in arbitrary order. /// /// The iterator element type is `(View, View)`. - pub fn iter(&self) -> MapIter<'_, K, V> { + pub fn iter(&self) -> MapIter { self.into_iter() } diff --git a/rust/upb.rs b/rust/upb.rs index f95b0753f..37d9158cf 100644 --- a/rust/upb.rs +++ b/rust/upb.rs @@ -717,19 +717,19 @@ macro_rules! impl_ProxiedInMapValue_for_non_generated_value_types { // No-op: the memory will be dropped by the arena. } - fn map_clear(mut map: Mut<'_, Map<$key_t, Self>>) { + fn map_clear(mut map: MapMut<$key_t, Self>) { unsafe { upb_Map_Clear(map.as_raw(Private)); } } - fn map_len(map: View<'_, Map<$key_t, Self>>) -> usize { + fn map_len(map: MapView<$key_t, Self>) -> usize { unsafe { upb_Map_Size(map.as_raw(Private)) } } - fn map_insert(mut map: Mut<'_, Map<$key_t, Self>>, key: View<'_, $key_t>, value: impl IntoProxied) -> bool { + fn map_insert(mut map: MapMut<$key_t, Self>, key: View<'_, $key_t>, value: impl IntoProxied) -> bool { let arena = map.raw_arena(Private); unsafe { upb_Map_InsertAndReturnIfInserted( @@ -741,7 +741,7 @@ macro_rules! impl_ProxiedInMapValue_for_non_generated_value_types { } } - fn map_get<'a>(map: View<'a, Map<$key_t, Self>>, key: View<'_, $key_t>) -> Option> { + fn map_get<'a>(map: MapView<'a, $key_t, Self>, key: View<'_, $key_t>) -> Option> { let mut val = MaybeUninit::uninit(); let found = unsafe { upb_Map_Get(map.as_raw(Private), <$key_t as UpbTypeConversions>::to_message_value(key), @@ -753,7 +753,7 @@ macro_rules! impl_ProxiedInMapValue_for_non_generated_value_types { Some(unsafe { <$t as UpbTypeConversions>::from_message_value(val.assume_init()) }) } - fn map_remove(mut map: Mut<'_, Map<$key_t, Self>>, key: View<'_, $key_t>) -> bool { + fn map_remove(mut map: MapMut<$key_t, Self>, key: View<'_, $key_t>) -> bool { unsafe { upb_Map_Delete(map.as_raw(Private), <$key_t as UpbTypeConversions>::to_message_value(key), @@ -761,7 +761,7 @@ macro_rules! impl_ProxiedInMapValue_for_non_generated_value_types { } } - fn map_iter(map: View<'_, Map<$key_t, Self>>) -> MapIter<'_, $key_t, Self> { + fn map_iter(map: MapView<$key_t, Self>) -> MapIter<$key_t, Self> { // SAFETY: View> guarantees its RawMap outlives '_. unsafe { MapIter::from_raw(Private, RawMapIter::new(map.as_raw(Private))) diff --git a/src/google/protobuf/compiler/rust/enum.cc b/src/google/protobuf/compiler/rust/enum.cc index c840d6c3a..dd9df5708 100644 --- a/src/google/protobuf/compiler/rust/enum.cc +++ b/src/google/protobuf/compiler/rust/enum.cc @@ -86,19 +86,19 @@ void EnumProxiedInMapValue(Context& ctx, const EnumDescriptor& desc) { unsafe { $pbr$::$map_free_thunk$(map.as_raw($pbi$::Private)); } } - fn map_clear(mut map: $pb$::Mut<'_, $pb$::Map<$key_t$, Self>>) { + fn map_clear(mut map: $pb$::MapMut<$key_t$, Self>) { unsafe { $pbr$::$map_clear_thunk$(map.as_raw($pbi$::Private)); } } - fn map_len(map: $pb$::View<'_, $pb$::Map<$key_t$, Self>>) -> usize { + fn map_len(map: $pb$::MapView<$key_t$, Self>) -> usize { unsafe { $pbr$::$map_size_thunk$(map.as_raw($pbi$::Private)) } } - fn map_insert(mut map: $pb$::Mut<'_, $pb$::Map<$key_t$, Self>>, key: $pb$::View<'_, $key_t$>, value: impl $pb$::IntoProxied) -> bool { + fn map_insert(mut map: $pb$::MapMut<$key_t$, Self>, key: $pb$::View<'_, $key_t$>, value: impl $pb$::IntoProxied) -> bool { unsafe { $pbr$::$map_insert_thunk$(map.as_raw($pbi$::Private), $to_ffi_key_expr$, value.into_proxied($pbi$::Private).0) } } - fn map_get<'a>(map: $pb$::View<'a, $pb$::Map<$key_t$, Self>>, key: $pb$::View<'_, $key_t$>) -> Option<$pb$::View<'a, Self>> { + fn map_get<'a>(map: $pb$::MapView<'a, $key_t$, Self>, key: $pb$::View<'_, $key_t$>) -> Option<$pb$::View<'a, Self>> { let key = $to_ffi_key_expr$; let mut value = $std$::mem::MaybeUninit::uninit(); let found = unsafe { $pbr$::$map_get_thunk$(map.as_raw($pbi$::Private), key, value.as_mut_ptr()) }; @@ -108,12 +108,12 @@ void EnumProxiedInMapValue(Context& ctx, const EnumDescriptor& desc) { Some(unsafe { $name$(value.assume_init()) }) } - fn map_remove(mut map: $pb$::Mut<'_, $pb$::Map<$key_t$, Self>>, key: $pb$::View<'_, $key_t$>) -> bool { + fn map_remove(mut map: $pb$::MapMut<$key_t$, Self>, key: $pb$::View<'_, $key_t$>) -> bool { let mut value = $std$::mem::MaybeUninit::uninit(); unsafe { $pbr$::$map_remove_thunk$(map.as_raw($pbi$::Private), $to_ffi_key_expr$, value.as_mut_ptr()) } } - fn map_iter(map: $pb$::View<'_, $pb$::Map<$key_t$, Self>>) -> $pb$::MapIter<'_, $key_t$, Self> { + fn map_iter(map: $pb$::MapView<$key_t$, Self>) -> $pb$::MapIter<$key_t$, Self> { // SAFETY: // - The backing map for `map.as_raw` is valid for at least '_. // - A View that is live for '_ guarantees the backing map is unmodified for '_. @@ -170,19 +170,19 @@ void EnumProxiedInMapValue(Context& ctx, const EnumDescriptor& desc) { // No-op: the memory will be dropped by the arena. } - fn map_clear(mut map: $pb$::Mut<'_, $pb$::Map<$key_t$, Self>>) { + fn map_clear(mut map: $pb$::MapMut<$key_t$, Self>) { unsafe { $pbr$::upb_Map_Clear(map.as_raw($pbi$::Private)); } } - fn map_len(map: $pb$::View<'_, $pb$::Map<$key_t$, Self>>) -> usize { + fn map_len(map: $pb$::MapView<$key_t$, Self>) -> usize { unsafe { $pbr$::upb_Map_Size(map.as_raw($pbi$::Private)) } } - fn map_insert(mut map: $pb$::Mut<'_, $pb$::Map<$key_t$, Self>>, key: $pb$::View<'_, $key_t$>, value: impl $pb$::IntoProxied) -> bool { + fn map_insert(mut map: $pb$::MapMut<$key_t$, Self>, key: $pb$::View<'_, $key_t$>, value: impl $pb$::IntoProxied) -> bool { let arena = map.inner($pbi$::Private).raw_arena(); unsafe { $pbr$::upb_Map_InsertAndReturnIfInserted( @@ -194,7 +194,7 @@ void EnumProxiedInMapValue(Context& ctx, const EnumDescriptor& desc) { } } - fn map_get<'a>(map: $pb$::View<'a, $pb$::Map<$key_t$, Self>>, key: $pb$::View<'_, $key_t$>) -> Option<$pb$::View<'a, Self>> { + fn map_get<'a>(map: $pb$::MapView<'a, $key_t$, Self>, key: $pb$::View<'_, $key_t$>) -> Option<$pb$::View<'a, Self>> { let mut val = $std$::mem::MaybeUninit::uninit(); let found = unsafe { $pbr$::upb_Map_Get( @@ -208,7 +208,7 @@ void EnumProxiedInMapValue(Context& ctx, const EnumDescriptor& desc) { Some($name$(unsafe { val.assume_init().int32_val })) } - fn map_remove(mut map: $pb$::Mut<'_, $pb$::Map<$key_t$, Self>>, key: $pb$::View<'_, $key_t$>) -> bool { + fn map_remove(mut map: $pb$::MapMut<$key_t$, Self>, key: $pb$::View<'_, $key_t$>) -> bool { let mut val = $std$::mem::MaybeUninit::uninit(); unsafe { $pbr$::upb_Map_Delete( @@ -217,7 +217,7 @@ void EnumProxiedInMapValue(Context& ctx, const EnumDescriptor& desc) { val.as_mut_ptr()) } } - fn map_iter(map: $pb$::View<'_, $pb$::Map<$key_t$, Self>>) -> $pb$::MapIter<'_, $key_t$, Self> { + fn map_iter(map: $pb$::MapView<$key_t$, Self>) -> $pb$::MapIter<$key_t$, Self> { // SAFETY: View> guarantees its RawMap outlives '_. unsafe { $pb$::MapIter::from_raw($pbi$::Private, $pbr$::RawMapIter::new(map.as_raw($pbi$::Private))) diff --git a/src/google/protobuf/compiler/rust/message.cc b/src/google/protobuf/compiler/rust/message.cc index 8c84cf98c..2dc17a3aa 100644 --- a/src/google/protobuf/compiler/rust/message.cc +++ b/src/google/protobuf/compiler/rust/message.cc @@ -615,16 +615,16 @@ void MessageProxiedInMapValue(Context& ctx, const Descriptor& msg) { unsafe { $pbr$::proto2_rust_map_free(map.as_raw($pbi$::Private), $key_is_string$, $map_size_info_thunk$($key_t$::SIZE_INFO_INDEX)); } } - fn map_clear(mut map: $pb$::Mut<'_, $pb$::Map<$key_t$, Self>>) { + fn map_clear(mut map: $pb$::MapMut<$key_t$, Self>) { use $pbr$::MapNodeSizeInfoIndexForType; unsafe { $pbr$::proto2_rust_map_clear(map.as_raw($pbi$::Private), $key_is_string$, $map_size_info_thunk$($key_t$::SIZE_INFO_INDEX)); } } - fn map_len(map: $pb$::View<'_, $pb$::Map<$key_t$, Self>>) -> usize { + fn map_len(map: $pb$::MapView<$key_t$, Self>) -> usize { unsafe { $pbr$::proto2_rust_map_size(map.as_raw($pbi$::Private)) } } - fn map_insert(mut map: $pb$::Mut<'_, $pb$::Map<$key_t$, Self>>, key: $pb$::View<'_, $key_t$>, value: impl $pb$::IntoProxied) -> bool { + fn map_insert(mut map: $pb$::MapMut<$key_t$, Self>, key: $pb$::View<'_, $key_t$>, value: impl $pb$::IntoProxied) -> bool { use $pbr$::MapNodeSizeInfoIndexForType; unsafe { $pbr$::$map_insert$( @@ -635,7 +635,7 @@ void MessageProxiedInMapValue(Context& ctx, const Descriptor& msg) { } } - fn map_get<'a>(map: $pb$::View<'a, $pb$::Map<$key_t$, Self>>, key: $pb$::View<'_, $key_t$>) -> Option<$pb$::View<'a, Self>> { + fn map_get<'a>(map: $pb$::MapView<'a, $key_t$, Self>, key: $pb$::View<'_, $key_t$>) -> Option<$pb$::View<'a, Self>> { use $pbr$::MapNodeSizeInfoIndexForType; let key = $key_expr$; let mut value = $std$::mem::MaybeUninit::uninit(); @@ -652,7 +652,7 @@ void MessageProxiedInMapValue(Context& ctx, const Descriptor& msg) { Some($Msg$View::new($pbi$::Private, unsafe { value.assume_init() })) } - fn map_remove(mut map: $pb$::Mut<'_, $pb$::Map<$key_t$, Self>>, key: $pb$::View<'_, $key_t$>) -> bool { + fn map_remove(mut map: $pb$::MapMut<$key_t$, Self>, key: $pb$::View<'_, $key_t$>) -> bool { use $pbr$::MapNodeSizeInfoIndexForType; unsafe { $pbr$::$map_remove$( @@ -662,7 +662,7 @@ void MessageProxiedInMapValue(Context& ctx, const Descriptor& msg) { } } - fn map_iter(map: $pb$::View<'_, $pb$::Map<$key_t$, Self>>) -> $pb$::MapIter<'_, $key_t$, Self> { + fn map_iter(map: $pb$::MapView<$key_t$, Self>) -> $pb$::MapIter<$key_t$, Self> { // SAFETY: // - The backing map for `map.as_raw` is valid for at least '_. // - A View that is live for '_ guarantees the backing map is unmodified for '_. @@ -756,19 +756,19 @@ void MessageProxiedInMapValue(Context& ctx, const Descriptor& msg) { // No-op: the memory will be dropped by the arena. } - fn map_clear(mut map: $pb$::Mut<'_, $pb$::Map<$key_t$, Self>>) { + fn map_clear(mut map: $pb$::MapMut<$key_t$, Self>) { unsafe { $pbr$::upb_Map_Clear(map.as_raw($pbi$::Private)); } } - fn map_len(map: $pb$::View<'_, $pb$::Map<$key_t$, Self>>) -> usize { + fn map_len(map: $pb$::MapView<$key_t$, Self>) -> usize { unsafe { $pbr$::upb_Map_Size(map.as_raw($pbi$::Private)) } } - fn map_insert(mut map: $pb$::Mut<'_, $pb$::Map<$key_t$, Self>>, key: $pb$::View<'_, $key_t$>, value: impl $pb$::IntoProxied) -> bool { + fn map_insert(mut map: $pb$::MapMut<$key_t$, Self>, key: $pb$::View<'_, $key_t$>, value: impl $pb$::IntoProxied) -> bool { let arena = map.inner($pbi$::Private).raw_arena(); unsafe { $pbr$::upb_Map_InsertAndReturnIfInserted( @@ -780,7 +780,7 @@ void MessageProxiedInMapValue(Context& ctx, const Descriptor& msg) { } } - fn map_get<'a>(map: $pb$::View<'a, $pb$::Map<$key_t$, Self>>, key: $pb$::View<'_, $key_t$>) -> Option<$pb$::View<'a, Self>> { + fn map_get<'a>(map: $pb$::MapView<'a, $key_t$, Self>, key: $pb$::View<'_, $key_t$>) -> Option<$pb$::View<'a, Self>> { let mut val = $std$::mem::MaybeUninit::uninit(); let found = unsafe { $pbr$::upb_Map_Get( @@ -794,7 +794,7 @@ void MessageProxiedInMapValue(Context& ctx, const Descriptor& msg) { Some(unsafe { ::from_message_value(val.assume_init()) }) } - fn map_remove(mut map: $pb$::Mut<'_, $pb$::Map<$key_t$, Self>>, key: $pb$::View<'_, $key_t$>) -> bool { + fn map_remove(mut map: $pb$::MapMut<$key_t$, Self>, key: $pb$::View<'_, $key_t$>) -> bool { unsafe { $pbr$::upb_Map_Delete( map.as_raw($pbi$::Private), @@ -802,8 +802,8 @@ void MessageProxiedInMapValue(Context& ctx, const Descriptor& msg) { $std$::ptr::null_mut()) } } - fn map_iter(map: $pb$::View<'_, $pb$::Map<$key_t$, Self>>) -> $pb$::MapIter<'_, $key_t$, Self> { - // SAFETY: View> guarantees its RawMap outlives '_. + fn map_iter(map: $pb$::MapView<$key_t$, Self>) -> $pb$::MapIter<$key_t$, Self> { + // SAFETY: MapView<'_,..>> guarantees its RawMap outlives '_. unsafe { $pb$::MapIter::from_raw($pbi$::Private, $pbr$::RawMapIter::new(map.as_raw($pbi$::Private))) }