Use MapView/MapMut instad of View<Map>/Mut<Map>

These types are effectively two ways to spell the same type, but MapView/MapMut is more terse, especially where the unnamed lifetime was used which can now be implied (`View<'_, Map<K, V>>` can just be `MapView<K,V>`)

PiperOrigin-RevId: 667636945
This commit is contained in:
Protobuf Team Bot 2024-08-26 10:44:26 -07:00 коммит произвёл Copybara-Service
Родитель 30a8ef5008
Коммит 9d3391f183
5 изменённых файлов: 46 добавлений и 50 удалений

Просмотреть файл

@ -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<Self>) -> bool {
fn map_insert(mut map: MapMut<$key_t, Self>, key: View<'_, $key_t>, value: impl IntoProxied<Self>) -> 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<View<'a, Self>> {
fn map_get<'a>(map: MapView<'a, $key_t, Self>, key: View<'_, $key_t>) -> Option<View<'a, Self>> {
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 '_.

Просмотреть файл

@ -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<K, Self>);
fn map_clear(map: Mut<'_, Map<K, Self>>);
fn map_len(map: View<'_, Map<K, Self>>) -> usize;
fn map_insert(
map: Mut<'_, Map<K, Self>>,
key: View<'_, K>,
value: impl IntoProxied<Self>,
) -> bool;
fn map_get<'a>(map: View<'a, Map<K, Self>>, key: View<'_, K>) -> Option<View<'a, Self>>;
fn map_remove(map: Mut<'_, Map<K, Self>>, key: View<'_, K>) -> bool;
fn map_clear(map: MapMut<K, Self>);
fn map_len(map: MapView<K, Self>) -> usize;
fn map_insert(map: MapMut<K, Self>, key: View<'_, K>, value: impl IntoProxied<Self>) -> bool;
fn map_get<'a>(map: MapView<'a, K, Self>, key: View<'_, K>) -> Option<View<'a, Self>>;
fn map_remove(map: MapMut<K, Self>, key: View<'_, K>) -> bool;
fn map_iter(map: View<'_, Map<K, Self>>) -> MapIter<'_, K, Self>;
fn map_iter(map: MapView<K, Self>) -> MapIter<K, Self>;
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<K>, View<V>)`.
pub fn iter(&self) -> MapIter<'_, K, V> {
pub fn iter(&self) -> MapIter<K, V> {
self.into_iter()
}

Просмотреть файл

@ -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<Self>) -> bool {
fn map_insert(mut map: MapMut<$key_t, Self>, key: View<'_, $key_t>, value: impl IntoProxied<Self>) -> 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<View<'a, Self>> {
fn map_get<'a>(map: MapView<'a, $key_t, Self>, key: View<'_, $key_t>) -> Option<View<'a, Self>> {
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<Map<'_,..>> guarantees its RawMap outlives '_.
unsafe {
MapIter::from_raw(Private, RawMapIter::new(map.as_raw(Private)))

Просмотреть файл

@ -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<Self>) -> bool {
fn map_insert(mut map: $pb$::MapMut<$key_t$, Self>, key: $pb$::View<'_, $key_t$>, value: impl $pb$::IntoProxied<Self>) -> 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<Self>) -> bool {
fn map_insert(mut map: $pb$::MapMut<$key_t$, Self>, key: $pb$::View<'_, $key_t$>, value: impl $pb$::IntoProxied<Self>) -> 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<Map<'_,..>> guarantees its RawMap outlives '_.
unsafe {
$pb$::MapIter::from_raw($pbi$::Private, $pbr$::RawMapIter::new(map.as_raw($pbi$::Private)))

Просмотреть файл

@ -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<Self>) -> bool {
fn map_insert(mut map: $pb$::MapMut<$key_t$, Self>, key: $pb$::View<'_, $key_t$>, value: impl $pb$::IntoProxied<Self>) -> 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<Self>) -> bool {
fn map_insert(mut map: $pb$::MapMut<$key_t$, Self>, key: $pb$::View<'_, $key_t$>, value: impl $pb$::IntoProxied<Self>) -> 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 { <Self as $pbr$::UpbTypeConversions>::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<Map<'_,..>> 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)))
}