@@ -13,13 +13,12 @@ pub struct Field {
1313 pub span : Span ,
1414 pub sql_type : Option < syn:: Type > ,
1515 pub flags : MetaItem ,
16- column_name_from_attribute : Option < syn :: Ident > ,
16+ column_name_from_attribute : Option < MetaItem > ,
1717}
1818
1919impl Field {
2020 pub fn from_struct_field ( field : & syn:: Field , index : usize ) -> Self {
21- let column_name_from_attribute =
22- MetaItem :: with_name ( & field. attrs , "column_name" ) . map ( |m| m. expect_ident_value ( ) ) ;
21+ let column_name_from_attribute = MetaItem :: with_name ( & field. attrs , "column_name" ) ;
2322 let name = match field. ident . clone ( ) {
2423 Some ( mut x) => {
2524 // https://github.com/rust-lang/rust/issues/47983#issuecomment-362817105
@@ -51,7 +50,8 @@ impl Field {
5150
5251 pub fn column_name ( & self ) -> syn:: Ident {
5352 self . column_name_from_attribute
54- . clone ( )
53+ . as_ref ( )
54+ . map ( |m| m. expect_ident_value ( ) )
5555 . unwrap_or_else ( || match self . name {
5656 FieldName :: Named ( ref x) => x. clone ( ) ,
5757 _ => {
@@ -65,6 +65,23 @@ impl Field {
6565 } )
6666 }
6767
68+ pub fn column_str_name ( & self ) -> String {
69+ self . column_name_from_attribute
70+ . as_ref ( )
71+ . map ( |m| {
72+ m. str_value ( ) . unwrap_or_else ( |e| {
73+ e. emit ( ) ;
74+ "unknown_column" . to_string ( )
75+ } )
76+ } )
77+ . unwrap_or_else ( || {
78+ self . span
79+ . error ( "All fields of tuple structs must be annotated with `#[column_name]`" )
80+ . emit ( ) ;
81+ "unknown_column" . to_string ( )
82+ } )
83+ }
84+
6885 pub fn has_flag ( & self , flag : & str ) -> bool {
6986 self . flags . has_flag ( flag)
7087 }
0 commit comments