@@ -41,16 +41,15 @@ pub fn entity_tx_context_def_type(entity_type: &Type) -> Type {
4141
4242#[ derive( Clone ) ]
4343pub struct TxContextItem {
44+ pub var_name : Ident ,
4445 pub definition : TokenStream ,
4546 pub def_constructor : TokenStream ,
4647 pub write_definition : TokenStream ,
47- pub write_constructor : TokenStream ,
4848 pub write_begin : TokenStream ,
4949 pub async_flush : Option < TokenStream > ,
5050 pub deferred_flush : Option < TokenStream > ,
5151 pub write_shutdown : TokenStream ,
5252 pub read_definition : TokenStream ,
53- pub read_constructor : TokenStream ,
5453}
5554
5655pub fn def_tx_context ( entity_def : & EntityDef , tx_contexts : & [ TxContextItem ] ) -> TokenStream {
@@ -78,7 +77,10 @@ pub fn def_tx_context(entity_def: &EntityDef, tx_contexts: &[TxContextItem]) ->
7877
7978pub fn write_tx_context ( entity_def : & EntityDef , tx_contexts : & [ TxContextItem ] ) -> TokenStream {
8079 let definitions: Vec < TokenStream > = tx_contexts. iter ( ) . map ( |item| item. write_definition . clone ( ) ) . collect ( ) ;
81- let constructors: Vec < TokenStream > = tx_contexts. iter ( ) . map ( |item| item. write_constructor . clone ( ) ) . collect ( ) ;
80+ let constructors: Vec < TokenStream > =
81+ tx_contexts. iter ( )
82+ . map ( |item| item. var_name . clone ( ) )
83+ . map ( |var_name| quote ! { #var_name: defs. #var_name. to_write_field( storage) ?} ) . collect ( ) ;
8284 let begins: Vec < TokenStream > = tx_contexts. iter ( ) . map ( |item| item. write_begin . clone ( ) ) . collect ( ) ;
8385 let shutdowns: Vec < TokenStream > = tx_contexts. iter ( ) . map ( |item| item. write_shutdown . clone ( ) ) . collect ( ) ;
8486 let async_flushes: Vec < TokenStream > = tx_contexts. iter ( ) . flat_map ( |item| item. async_flush . clone ( ) ) . collect ( ) ;
@@ -123,7 +125,10 @@ pub fn write_tx_context(entity_def: &EntityDef, tx_contexts: &[TxContextItem]) -
123125
124126pub fn read_tx_context ( entity_def : & EntityDef , tx_contexts : & [ TxContextItem ] ) -> TokenStream {
125127 let definitions: Vec < TokenStream > = tx_contexts. iter ( ) . map ( |item| item. read_definition . clone ( ) ) . collect ( ) ;
126- let constructors: Vec < TokenStream > = tx_contexts. iter ( ) . map ( |item| item. read_constructor . clone ( ) ) . collect ( ) ;
128+ let constructors: Vec < TokenStream > =
129+ tx_contexts. iter ( )
130+ . map ( |item| item. var_name . clone ( ) )
131+ . map ( |var_name| quote ! { #var_name: defs. #var_name. to_read_field( storage) ?} ) . collect ( ) ;
127132 let entity_tx_context_ty = & entity_def. ctx_type ;
128133 let read_tx_context_ty = & entity_def. read_ctx_type ;
129134 let read_tx_context_name = tx_context_name ( TxType :: Read ) ;
@@ -182,12 +187,6 @@ pub fn tx_context_plain_item(def: &PlainTableDef) -> TxContextItem {
182187 PlainFactory :: new( #name_lit, #table_def) ,
183188 )
184189 } ;
185- let write_constructor = quote ! {
186- #var_ident: defs. #var_ident. to_write_field( storage) ?
187- } ;
188- let read_constructor = quote ! {
189- #var_ident: defs. #var_ident. to_read_field( storage) ?
190- } ;
191190 let write_begin = quote ! { self . #var_ident. begin_async( durability) ? } ;
192191 let async_flush =
193192 if def. root_pk {
@@ -199,16 +198,15 @@ pub fn tx_context_plain_item(def: &PlainTableDef) -> TxContextItem {
199198 let write_shutdown = quote ! { self . #var_ident. shutdown_async( ) ? } ;
200199
201200 TxContextItem {
201+ var_name : var_ident. clone ( ) ,
202202 definition,
203203 def_constructor,
204204 write_definition,
205- write_constructor,
206205 write_begin,
207206 async_flush,
208207 deferred_flush,
209208 write_shutdown,
210209 read_definition,
211- read_constructor,
212210 }
213211}
214212
@@ -243,28 +241,21 @@ pub fn tx_context_index_item(defs: &IndexTableDefs) -> TxContextItem {
243241 IndexFactory :: new( #name_lit, #lru_cache, #pk_by_index, #index_by_pk) ,
244242 )
245243 } ;
246- let write_constructor = quote ! {
247- #var_ident: defs. #var_ident. to_write_field( storage) ?
248- } ;
249- let read_constructor = quote ! {
250- #var_ident: defs. #var_ident. to_read_field( storage) ?
251- } ;
252244 let write_begin = quote ! { self . #var_ident. begin_async( durability) ? } ;
253245 let async_flush = Some ( quote ! { self . #var_ident. flush_async( ) ? } ) ;
254246 let deferred_flush = Some ( quote ! { self . #var_ident. flush_deferred( ) ? } ) ;
255247 let write_shutdown = quote ! { self . #var_ident. shutdown_async( ) ? } ;
256248
257249 TxContextItem {
250+ var_name : var_ident. clone ( ) ,
258251 definition,
259252 def_constructor,
260253 write_definition,
261- write_constructor,
262254 write_begin,
263255 async_flush,
264256 deferred_flush,
265257 write_shutdown,
266258 read_definition,
267- read_constructor,
268259 }
269260}
270261
@@ -301,29 +292,21 @@ pub fn tx_context_dict_item(defs: &DictTableDefs) -> TxContextItem {
301292 DictFactory :: new( #name_lit, #lru_cache, #dict_pk_to_ids, #value_by_dict, #value_to_dict, #dict_pk_by_pk) ,
302293 )
303294 } ;
304- let write_constructor = quote ! {
305- #var_ident: defs. #var_ident. to_write_field( storage) ?
306- } ;
307- let read_constructor = quote ! {
308- #var_ident: defs. #var_ident. to_read_field( storage) ?
309- } ;
310-
311295 let write_begin = quote ! { self . #var_ident. begin_async( durability) ? } ;
312296 let async_flush = Some ( quote ! { self . #var_ident. flush_async( ) ? } ) ;
313297 let deferred_flush = Some ( quote ! { self . #var_ident. flush_deferred( ) ? } ) ;
314298 let write_shutdown = quote ! { self . #var_ident. shutdown_async( ) ? } ;
315299
316300 TxContextItem {
301+ var_name : var_ident. clone ( ) ,
317302 definition,
318303 def_constructor,
319304 write_definition,
320- write_constructor,
321305 write_begin,
322306 async_flush,
323307 deferred_flush,
324308 write_shutdown,
325309 read_definition,
326- read_constructor,
327310 }
328311}
329312
0 commit comments