@@ -451,13 +451,12 @@ fn superize_vis(vis: &syn::Visibility) -> Cow<'_, syn::Visibility> {
451451 }
452452}
453453
454- #[ derive( Clone ) ]
454+ #[ derive( Copy , Clone ) ]
455455struct Column < ' a > {
456456 index : u16 ,
457457 vis : & ' a syn:: Visibility ,
458458 ident : & ' a syn:: Ident ,
459459 ty : & ' a syn:: Type ,
460- default_value : Option < syn:: Expr > ,
461460}
462461
463462fn try_find_column < ' a , ' b , T : ?Sized > ( cols : & ' a [ Column < ' b > ] , name : & T ) -> Option < & ' a Column < ' b > >
@@ -476,7 +475,6 @@ enum ColumnAttr {
476475 AutoInc ( Span ) ,
477476 PrimaryKey ( Span ) ,
478477 Index ( IndexArg ) ,
479- Default ( syn:: Expr , Span ) ,
480478}
481479
482480impl ColumnAttr {
@@ -496,25 +494,12 @@ impl ColumnAttr {
496494 } else if ident == sym:: primary_key {
497495 attr. meta . require_path_only ( ) ?;
498496 Some ( ColumnAttr :: PrimaryKey ( ident. span ( ) ) )
499- } else if ident == sym:: default {
500- Some ( parse_default_attr ( attr, ident) ?)
501497 } else {
502498 None
503499 } )
504500 }
505501}
506502
507- fn parse_default_attr ( attr : & syn:: Attribute , ident : & Ident ) -> syn:: Result < ColumnAttr > {
508- if let Ok ( expr) = attr. parse_args :: < syn:: Expr > ( ) {
509- return Ok ( ColumnAttr :: Default ( expr, ident. span ( ) ) ) ;
510- }
511-
512- Err ( syn:: Error :: new_spanned (
513- & attr. meta ,
514- "expected default value in format `#[default(CONSTANT_VALUE)]`" ,
515- ) )
516- }
517-
518503pub ( crate ) fn table_impl ( mut args : TableArgs , item : & syn:: DeriveInput ) -> syn:: Result < TokenStream > {
519504 let vis = & item. vis ;
520505 let sats_ty = sats:: sats_type_from_derive ( item, quote ! ( spacetimedb:: spacetimedb_lib) ) ?;
@@ -563,7 +548,6 @@ pub(crate) fn table_impl(mut args: TableArgs, item: &syn::DeriveInput) -> syn::R
563548 let mut unique = None ;
564549 let mut auto_inc = None ;
565550 let mut primary_key = None ;
566- let mut default_value = None ;
567551 for attr in field. original_attrs {
568552 let Some ( attr) = ColumnAttr :: parse ( attr, field_ident) ? else {
569553 continue ;
@@ -582,42 +566,28 @@ pub(crate) fn table_impl(mut args: TableArgs, item: &syn::DeriveInput) -> syn::R
582566 primary_key = Some ( span) ;
583567 }
584568 ColumnAttr :: Index ( index_arg) => args. indices . push ( index_arg) ,
585- ColumnAttr :: Default ( expr, span) => {
586- check_duplicate ( & default_value, span) ?;
587- default_value = Some ( expr) ;
588- }
589569 }
590570 }
591571
592- if let Some ( default_value) = & default_value {
593- if auto_inc. is_some ( ) || primary_key. is_some ( ) || unique. is_some ( ) {
594- return Err ( syn:: Error :: new (
595- default_value. span ( ) ,
596- "invalid combination: auto_inc, unique index or primary key cannot have a default value" ,
597- ) ) ;
598- } ;
599- }
600-
601572 let column = Column {
602573 index : col_num,
603574 ident : field_ident,
604575 vis : field. vis ,
605576 ty : field. ty ,
606- default_value,
607577 } ;
608578
609579 if unique. is_some ( ) || primary_key. is_some ( ) {
610- unique_columns. push ( column. clone ( ) ) ;
580+ unique_columns. push ( column) ;
611581 }
612582 if auto_inc. is_some ( ) {
613- sequenced_columns. push ( column. clone ( ) ) ;
583+ sequenced_columns. push ( column) ;
614584 }
615585 if let Some ( span) = primary_key {
616586 check_duplicate_msg ( & primary_key_column, span, "can only have one primary key per table" ) ?;
617- primary_key_column = Some ( column. clone ( ) ) ;
587+ primary_key_column = Some ( column) ;
618588 }
619589
620- columns. push ( column. clone ( ) ) ;
590+ columns. push ( column) ;
621591 }
622592
623593 let row_type = quote ! ( #original_struct_ident) ;
@@ -677,45 +647,9 @@ pub(crate) fn table_impl(mut args: TableArgs, item: &syn::DeriveInput) -> syn::R
677647
678648 let table_access = args. access . iter ( ) . map ( |acc| acc. to_value ( ) ) ;
679649 let unique_col_ids = unique_columns. iter ( ) . map ( |col| col. index ) ;
680- let primary_col_id = primary_key_column. clone ( ) . into_iter ( ) . map ( |col| col. index ) ;
650+ let primary_col_id = primary_key_column. iter ( ) . map ( |col| col. index ) ;
681651 let sequence_col_ids = sequenced_columns. iter ( ) . map ( |col| col. index ) ;
682652
683- let default_type_check: TokenStream = columns
684- . iter ( )
685- . filter_map ( |col| {
686- if let Some ( val) = & col. default_value {
687- let ty = & col. ty ;
688- let ident_span = col. ident . span ( ) ;
689- Some ( quote_spanned ! { ident_span =>
690- // This closure enforces that `val` is of type `ty` at compile-time.
691- let _check: #ty = #val;
692- } )
693- } else {
694- None
695- }
696- } )
697- . collect ( ) ;
698-
699- let col_defaults: Vec < TokenStream > = columns. iter ( ) . filter_map ( |col| {
700- if let Some ( val) = & col. default_value {
701- let col_id = col. index ;
702- Some ( quote ! {
703- spacetimedb:: table:: ColumnDefault {
704- col_id: #col_id,
705- value: #val. serialize( spacetimedb:: sats:: algebraic_value:: ser:: ValueSerializer ) . expect( "default value serialization failed" ) ,
706- }
707- } )
708- } else {
709- None
710- }
711- } ) . collect ( ) ;
712-
713- let default_fn: TokenStream = quote ! {
714- fn get_default_col_values( ) -> Vec <spacetimedb:: table:: ColumnDefault > {
715- [ #( #col_defaults) * ] . to_vec( )
716- }
717- } ;
718-
719653 let ( schedule, schedule_typecheck) = args
720654 . scheduled
721655 . as_ref ( )
@@ -785,7 +719,6 @@ pub(crate) fn table_impl(mut args: TableArgs, item: &syn::DeriveInput) -> syn::R
785719 let field_types = fields. iter ( ) . map ( |f| f. ty ) . collect :: < Vec < _ > > ( ) ;
786720
787721 let tabletype_impl = quote ! {
788- use spacetimedb:: Serialize ;
789722 impl spacetimedb:: Table for #tablehandle_ident {
790723 type Row = #row_type;
791724
@@ -805,7 +738,6 @@ pub(crate) fn table_impl(mut args: TableArgs, item: &syn::DeriveInput) -> syn::R
805738 #( const SCHEDULE : Option <spacetimedb:: table:: ScheduleDesc <' static >> = Some ( #schedule) ; ) *
806739
807740 #table_id_from_name_func
808- #default_fn
809741 }
810742 } ;
811743
@@ -841,7 +773,6 @@ pub(crate) fn table_impl(mut args: TableArgs, item: &syn::DeriveInput) -> syn::R
841773 const _: ( ) = {
842774 #( let _ = <#field_types as spacetimedb:: rt:: TableColumn >:: _ITEM; ) *
843775 #schedule_typecheck
844- #default_type_check
845776 } ;
846777
847778 #trait_def
0 commit comments