@@ -152,16 +152,16 @@ impl<C: Configuration> IngredientImpl<C> {
152152 durabilities : C :: Durabilities ,
153153 ) -> C :: Struct {
154154 let id = self . singleton . with_scope ( || {
155- let ( id , _ ) = zalsa_local. allocate ( zalsa , self . ingredient_index , |_| Value :: < C > {
156- fields ,
157- revisions ,
158- durabilities ,
159- // SAFETY: We only ever access the memos of a value that we allocated through
160- // our `MemoTableTypes`.
161- memos : unsafe { MemoTable :: new ( self . memo_table_types ( ) ) } ,
162- } ) ;
163-
164- id
155+ zalsa_local
156+ . allocate ( zalsa , self . ingredient_index , |_| Value :: < C > {
157+ fields ,
158+ revisions ,
159+ durabilities ,
160+ // SAFETY: We only ever access the memos of a value that we allocated through
161+ // our `MemoTableTypes`.
162+ memos : unsafe { MemoTable :: new ( self . memo_table_types ( ) ) } ,
163+ } )
164+ . 0
165165 } ) ;
166166
167167 FromIdWithDb :: from_id ( id, zalsa)
@@ -440,10 +440,11 @@ where
440440mod persistence {
441441 use std:: fmt;
442442
443- use serde:: ser:: SerializeMap ;
443+ use serde:: ser:: { SerializeMap , SerializeStruct } ;
444444 use serde:: { de, Deserialize } ;
445445
446446 use super :: { Configuration , IngredientImpl , Value } ;
447+ use crate :: input:: singleton:: SingletonChoice ;
447448 use crate :: plumbing:: Ingredient ;
448449 use crate :: table:: memo:: MemoTable ;
449450 use crate :: zalsa:: Zalsa ;
@@ -467,7 +468,8 @@ mod persistence {
467468 {
468469 let Self { zalsa, .. } = self ;
469470
470- let mut map = serializer. serialize_map ( None ) ?;
471+ let count = zalsa. table ( ) . slots_of :: < Value < C > > ( ) . count ( ) ;
472+ let mut map = serializer. serialize_map ( Some ( count) ) ?;
471473
472474 for ( id, value) in zalsa. table ( ) . slots_of :: < Value < C > > ( ) {
473475 map. serialize_entry ( & id. as_bits ( ) , value) ?;
@@ -485,21 +487,7 @@ mod persistence {
485487 where
486488 S : serde:: Serializer ,
487489 {
488- let mut map = serializer. serialize_map ( None ) ?;
489-
490- struct SerializeFields < ' db , C : Configuration > ( & ' db C :: Fields ) ;
491-
492- impl < C > serde:: Serialize for SerializeFields < ' _ , C >
493- where
494- C : Configuration ,
495- {
496- fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
497- where
498- S : serde:: Serializer ,
499- {
500- C :: serialize ( self . 0 , serializer)
501- }
502- }
490+ let mut value = serializer. serialize_struct ( "Value" , 3 ) ?;
503491
504492 let Value {
505493 fields,
@@ -508,11 +496,25 @@ mod persistence {
508496 memos : _,
509497 } = self ;
510498
511- map . serialize_entry ( & "durabilities" , & durabilities) ?;
512- map . serialize_entry ( & "revisions" , & revisions) ?;
513- map . serialize_entry ( & "fields" , & SerializeFields :: < C > ( fields) ) ?;
499+ value . serialize_field ( "durabilities" , & durabilities) ?;
500+ value . serialize_field ( "revisions" , & revisions) ?;
501+ value . serialize_field ( "fields" , & SerializeFields :: < C > ( fields) ) ?;
514502
515- map. end ( )
503+ value. end ( )
504+ }
505+ }
506+
507+ struct SerializeFields < ' db , C : Configuration > ( & ' db C :: Fields ) ;
508+
509+ impl < C > serde:: Serialize for SerializeFields < ' _ , C >
510+ where
511+ C : Configuration ,
512+ {
513+ fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
514+ where
515+ S : serde:: Serializer ,
516+ {
517+ C :: serialize ( self . 0 , serializer)
516518 }
517519 }
518520
@@ -577,13 +579,14 @@ mod persistence {
577579 // Initialize the slot.
578580 //
579581 // SAFETY: We have a mutable reference to the database.
580- let ( allocated_id, _ ) = unsafe {
582+ let allocated_id = ingredient . singleton . with_scope ( || unsafe {
581583 zalsa
582584 . table ( )
583585 . page ( page_idx)
584586 . allocate ( page_idx, |_| value)
585587 . unwrap_or_else ( |_| panic ! ( "serialized an invalid `Id`: {id:?}" ) )
586- } ;
588+ . 0
589+ } ) ;
587590
588591 assert_eq ! (
589592 allocated_id, id,
@@ -596,6 +599,7 @@ mod persistence {
596599 }
597600
598601 #[ derive( Deserialize ) ]
602+ #[ serde( rename = "Value" ) ]
599603 pub struct DeserializeValue < C : Configuration > {
600604 durabilities : C :: Durabilities ,
601605 revisions : C :: Revisions ,
0 commit comments