@@ -57,25 +57,10 @@ fn impl_iden_for_unit_struct(
5757 table_name : & str ,
5858) -> proc_macro2:: TokenStream {
5959 let sea_query_path = sea_query_path ( ) ;
60-
61- if is_static_iden ( table_name) {
62- quote ! {
63- impl #sea_query_path:: Iden for #ident {
64- fn quoted( & self ) -> std:: borrow:: Cow <' static , str > {
65- std:: borrow:: Cow :: Borrowed ( #table_name)
66- }
67-
68- fn unquoted( & self ) -> & str {
69- #table_name
70- }
71- }
72- }
73- } else {
74- quote ! {
75- impl #sea_query_path:: Iden for #ident {
76- fn unquoted( & self ) -> & str {
77- #table_name
78- }
60+ quote ! {
61+ impl #sea_query_path:: IdenStatic for #ident {
62+ fn as_str( & self ) -> & ' static str {
63+ #table_name
7964 }
8065 }
8166 }
@@ -91,43 +76,19 @@ where
9176{
9277 let sea_query_path = sea_query_path ( ) ;
9378
94- let mut is_all_static_iden = true ;
95-
9679 let match_arms = match variants
97- . map ( |v| {
98- let v = IdenVariant :: < DeriveIden > :: try_from ( ( table_name, v) ) ?;
99- is_all_static_iden &= v. is_static_iden ( ) ;
100- Ok ( v)
101- } )
80+ . map ( |v| IdenVariant :: < DeriveIden > :: try_from ( ( table_name, v) ) )
10281 . collect :: < syn:: Result < Vec < _ > > > ( )
10382 {
10483 Ok ( v) => v,
10584 Err ( e) => return e. to_compile_error ( ) ,
10685 } ;
10786
108- if is_all_static_iden {
109- quote ! {
110- impl #sea_query_path:: Iden for #ident {
111- fn quoted( & self ) -> std:: borrow:: Cow <' static , str > {
112- std:: borrow:: Cow :: Borrowed ( match self {
113- #( #match_arms) , *
114- } )
115- }
116-
117- fn unquoted( & self ) -> & str {
118- match self {
119- #( #match_arms) , *
120- }
121- }
122- }
123- }
124- } else {
125- quote ! {
126- impl #sea_query_path:: Iden for #ident {
127- fn unquoted( & self ) -> & str {
128- match self {
129- #( #match_arms) , *
130- }
87+ quote ! {
88+ impl #sea_query_path:: IdenStatic for #ident {
89+ fn as_str( & self ) -> & ' static str {
90+ match self {
91+ #( #match_arms) , *
13192 }
13293 }
13394 }
@@ -190,11 +151,3 @@ fn find_attr(attrs: &[Attribute]) -> Option<&Attribute> {
190151 attr. path ( ) . is_ident ( & IdenPath :: Iden ) || attr. path ( ) . is_ident ( & IdenPath :: Method )
191152 } )
192153}
193-
194- pub fn is_static_iden ( name : & str ) -> bool {
195- // can only begin with [a-z_]
196- name. chars ( )
197- . take ( 1 )
198- . all ( |c| c == '_' || c. is_ascii_alphabetic ( ) )
199- && name. chars ( ) . all ( |c| c == '_' || c. is_ascii_alphanumeric ( ) )
200- }
0 commit comments