#protobuf #rust Mark {Map, Repeated}::new() as public

* Matches the C++ Protobuf API.
 * Improves ergonomics by allowing users to provide Into, FromIterator, et. al. implementations.
 * Allows owned types to be returned from functions.

PiperOrigin-RevId: 615008080
pull/16129/head
Jakob Buchgraber 10 months ago committed by Copybara-Service
parent 9ff062cd34
commit ad5e55ab92
  1. 13
      rust/map.rs
  2. 9
      rust/repeated.rs

@ -163,8 +163,7 @@ where
K: Proxied + ?Sized, K: Proxied + ?Sized,
V: ProxiedInMapValue<K> + ?Sized, V: ProxiedInMapValue<K> + ?Sized,
{ {
#[allow(dead_code)] pub fn new() -> Self {
pub(crate) fn new() -> Self {
V::map_new(Private) V::map_new(Private)
} }
@ -186,6 +185,16 @@ where
} }
} }
impl<K, V> Default for Map<K, V>
where
K: Proxied + ?Sized,
V: ProxiedInMapValue<K> + ?Sized,
{
fn default() -> Self {
Map::new()
}
}
#[doc(hidden)] #[doc(hidden)]
impl<'msg, K: ?Sized, V: ?Sized> MapView<'msg, K, V> { impl<'msg, K: ?Sized, V: ?Sized> MapView<'msg, K, V> {
#[doc(hidden)] #[doc(hidden)]

@ -280,8 +280,7 @@ pub struct Repeated<T: ?Sized + ProxiedInRepeated> {
} }
impl<T: ?Sized + ProxiedInRepeated> Repeated<T> { impl<T: ?Sized + ProxiedInRepeated> Repeated<T> {
#[allow(dead_code)] pub fn new() -> Self {
pub(crate) fn new() -> Self {
T::repeated_new(Private) T::repeated_new(Private)
} }
@ -294,6 +293,12 @@ impl<T: ?Sized + ProxiedInRepeated> Repeated<T> {
} }
} }
impl<T: ?Sized + ProxiedInRepeated> Default for Repeated<T> {
fn default() -> Self {
Repeated::new()
}
}
impl<T: ?Sized + ProxiedInRepeated> Drop for Repeated<T> { impl<T: ?Sized + ProxiedInRepeated> Drop for Repeated<T> {
fn drop(&mut self) { fn drop(&mut self) {
// SAFETY: only called once // SAFETY: only called once

Loading…
Cancel
Save