@ -9,7 +9,7 @@
use crate ::__internal ::{ Enum , Private , PtrAndLen , RawArena , RawMap , RawMessage , RawRepeatedField } ;
use crate ::{
Map , MapView , Mut , ProtoStr , Proxied , ProxiedInMapValue , ProxiedInRepeated , Repeated ,
Map , MapMut , Map View , Mut , ProtoStr , Proxied , ProxiedInMapValue , ProxiedInRepeated , Repeated ,
RepeatedMut , RepeatedView , SettableValue , View , ViewProxy ,
} ;
use core ::fmt ::Debug ;
@ -511,7 +511,7 @@ macro_rules! impl_repeated_primitives {
// - `copy_nonoverlapping` is unsafe but here we guarantee that both pointers
// are valid, the pointers are `#[repr(u8)]`, and the size is correct.
unsafe {
if ( ! upb_Array_Resize ( dest . as_raw ( Private ) , src . len ( ) , dest . inner . arena ) ) {
if ( ! upb_Array_Resize ( dest . as_raw ( Private ) , src . len ( ) , dest . raw_arena ( Private ) ) ) {
panic! ( "upb_Array_Resize failed." ) ;
}
ptr ::copy_nonoverlapping (
@ -528,7 +528,7 @@ macro_rules! impl_repeated_primitives {
impl < ' msg , T : ? Sized > RepeatedMut < ' msg , T > {
// Returns a `RawArena` which is live for at least `'msg`
#[ doc(hidden) ]
pub fn raw_arena ( & self , _private : Private ) -> RawArena {
pub fn raw_arena ( & mut self , _private : Private ) -> RawArena {
self . inner . arena
}
}
@ -598,7 +598,7 @@ pub fn cast_enum_repeated_mut<E: Enum + ProxiedInRepeated>(
// - Reading an enum array as an i32 array is sound.
// - No shared mutation is possible through the output.
unsafe {
let InnerRepeatedMut { arena , raw , .. } = repeated . into_in ner ( ) ;
let InnerRepeatedMut { arena , raw , .. } = repeated . inner ;
RepeatedMut ::from_inner ( private , InnerRepeatedMut { arena , raw , _phantom : PhantomData } )
}
}
@ -649,6 +649,14 @@ where
}
}
impl < ' msg , K : ? Sized , V : ? Sized > MapMut < ' msg , K , V > {
// Returns a `RawArena` which is live for at least `'msg`
#[ doc(hidden) ]
pub fn raw_arena ( & mut self , _private : Private ) -> RawArena {
self . inner . raw_arena
}
}
#[ derive(Clone, Copy, Debug) ]
pub struct InnerMapMut < ' msg > {
pub ( crate ) raw : RawMap ,
@ -814,29 +822,30 @@ macro_rules! impl_ProxiedInMapValue_for_non_generated_value_types {
// - `map.inner.raw_arena` is a live `upb_Arena*`
// - This function is only called once for `map` in `Drop`.
unsafe {
upb_Arena_Free ( map . inner . raw_arena ) ;
upb_Arena_Free ( map . as_mut ( ) . raw_arena ( Private ) ) ;
}
}
fn map_clear ( map : Mut < ' _ , Map < $key_t , Self > > ) {
fn map_clear ( mut map : Mut < ' _ , Map < $key_t , Self > > ) {
unsafe {
upb_Map_Clear ( map . inner . raw ) ;
upb_Map_Clear ( map . as_raw ( Private ) ) ;
}
}
fn map_len ( map : View < ' _ , Map < $key_t , Self > > ) -> usize {
unsafe {
upb_Map_Size ( map . raw )
upb_Map_Size ( map . as_ raw( Private ) )
}
}
fn map_insert ( map : Mut < ' _ , Map < $key_t , Self > > , key : View < ' _ , $key_t > , value : View < ' _ , Self > ) -> bool {
fn map_insert ( mut map : Mut < ' _ , Map < $key_t , Self > > , key : View < ' _ , $key_t > , value : View < ' _ , Self > ) -> bool {
let arena = map . raw_arena ( Private ) ;
unsafe {
upb_Map_InsertAndReturnIfInserted (
map . inner . raw ,
map . as_raw ( Private ) ,
< $key_t as UpbTypeConversions > ::to_message_value ( key ) ,
< $t as UpbTypeConversions > ::to_message_value_copy_if_required ( map . inner . raw_ arena, value ) ,
map . inner . raw_ arena
< $t as UpbTypeConversions > ::to_message_value_copy_if_required ( arena , value ) ,
arena
)
}
}
@ -844,7 +853,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 > > {
let mut val = < $t as UpbTypeConversions > ::empty_message_value ( ) ;
let found = unsafe {
upb_Map_Get ( map . raw , < $key_t as UpbTypeConversions > ::to_message_value ( key ) ,
upb_Map_Get ( map . as_ raw( Private ) , < $key_t as UpbTypeConversions > ::to_message_value ( key ) ,
& mut val )
} ;
if ! found {
@ -853,10 +862,10 @@ macro_rules! impl_ProxiedInMapValue_for_non_generated_value_types {
Some ( unsafe { < $t as UpbTypeConversions > ::from_message_value ( val ) } )
}
fn map_remove ( map : Mut < ' _ , Map < $key_t , Self > > , key : View < ' _ , $key_t > ) -> bool {
fn map_remove ( mut map : Mut < ' _ , Map < $key_t , Self > > , key : View < ' _ , $key_t > ) -> bool {
let mut val = < $t as UpbTypeConversions > ::empty_message_value ( ) ;
unsafe {
upb_Map_Delete ( map . inner . raw ,
upb_Map_Delete ( map . as_raw ( Private ) ,
< $key_t as UpbTypeConversions > ::to_message_value ( key ) ,
& mut val )
}