@@ -3,6 +3,7 @@ use crate::sym;
33use crate :: util:: { check_duplicate, check_duplicate_msg, ident_to_litstr, match_meta} ;
44use core:: slice;
55use heck:: ToSnakeCase ;
6+ use proc_macro_type_name:: ToTypeName ;
67use proc_macro2:: { Span , TokenStream } ;
78use quote:: { format_ident, quote, quote_spanned, ToTokens } ;
89use std:: borrow:: Cow ;
@@ -784,6 +785,9 @@ pub(crate) fn table_impl(mut args: TableArgs, item: &syn::DeriveInput) -> syn::R
784785 }
785786 } ;
786787
788+ let pk_type = primary_key_column. clone ( ) . map ( |x| x. ty ) ;
789+ let pk_type_ident = primary_key_column. clone ( ) . map ( |x| Ident :: new ( & ( original_struct_ident. to_string ( ) + & ( & x. ident ) . to_type_ident ( x. ident . span ( ) ) . to_string ( ) ) , x. ident . span ( ) ) ) ;
790+
787791 let ( schedule, schedule_typecheck) = args
788792 . scheduled
789793 . as_ref ( )
@@ -887,6 +891,18 @@ pub(crate) fn table_impl(mut args: TableArgs, item: &syn::DeriveInput) -> syn::R
887891 } ;
888892
889893 // Output all macro data
894+
895+ let trait_def_pk = pk_type. map ( |pk_type| quote_spanned ! { table_ident. span( ) =>
896+ #[ allow( dead_code) ]
897+ #[ derive( SpacetimeType ) ]
898+ struct #pk_type_ident( #pk_type) ;
899+ impl std:: borrow:: Borrow <#pk_type> for #pk_type_ident {
900+ fn borrow( & self ) -> & #pk_type {
901+ & self . 0
902+ }
903+ }
904+ } ) ;
905+
890906 let trait_def = quote_spanned ! { table_ident. span( ) =>
891907 #[ allow( non_camel_case_types, dead_code) ]
892908 #vis trait #table_ident {
@@ -931,6 +947,7 @@ pub(crate) fn table_impl(mut args: TableArgs, item: &syn::DeriveInput) -> syn::R
931947 #default_type_check
932948 } ;
933949
950+ #trait_def_pk
934951 #trait_def
935952 #trait_def_view
936953
0 commit comments