6161 }
6262}
6363
64+ fn impl_transparent ( ty : & Type ) -> TokenStream {
65+ quote ! {
66+ <#ty as _h5:: types:: H5Type >:: type_descriptor( )
67+ }
68+ }
69+
6470fn impl_enum ( names : Vec < Ident > , values : Vec < Expr > , repr : & Ident ) -> TokenStream {
6571 let size = Ident :: new (
6672 & format ! (
@@ -149,12 +155,18 @@ fn impl_trait(
149155 if fields. is_empty ( ) {
150156 panic ! ( "Cannot derive H5Type for empty structs" ) ;
151157 }
152- find_repr ( attrs, & [ "C" , "packed" ] )
153- . expect ( "H5Type requires #[repr(C)] or #[repr(packed)] for structs" ) ;
154- let types = pluck ( fields. iter ( ) , |f| f. ty . clone ( ) ) ;
155- let fields = pluck ( fields. iter ( ) , |f| f. ident . clone ( ) . unwrap ( ) ) ;
156- let names = fields. iter ( ) . map ( |f| f. to_string ( ) ) . collect :: < Vec < _ > > ( ) ;
157- impl_compound ( ty, ty_generics, & fields, & names, & types)
158+ if find_repr ( attrs, & [ "C" , "packed" , "transparent" ] ) . expect (
159+ "H5Type requires repr(C), repr(packed) or repr(transparent) for structs" ,
160+ ) == "transparent"
161+ {
162+ assert_eq ! ( fields. len( ) , 1 ) ;
163+ impl_transparent ( & fields[ 0 ] . ty )
164+ } else {
165+ let types = pluck ( fields. iter ( ) , |f| f. ty . clone ( ) ) ;
166+ let fields = pluck ( fields. iter ( ) , |f| f. ident . clone ( ) . unwrap ( ) ) ;
167+ let names = fields. iter ( ) . map ( |f| f. to_string ( ) ) . collect :: < Vec < _ > > ( ) ;
168+ impl_compound ( ty, ty_generics, & fields, & names, & types)
169+ }
158170 }
159171 Fields :: Unnamed ( ref fields) => {
160172 let ( index, fields) : ( Vec < Index > , Vec < _ > ) = fields
@@ -167,11 +179,17 @@ fn impl_trait(
167179 if fields. is_empty ( ) {
168180 panic ! ( "Cannot derive H5Type for empty tuple structs" ) ;
169181 }
170- find_repr ( attrs, & [ "C" , "packed" ] )
171- . expect ( "H5Type requires #[repr(C)] or #[repr(packed)] for structs" ) ;
172- let names = ( 0 ..fields. len ( ) ) . map ( |f| f. to_string ( ) ) . collect :: < Vec < _ > > ( ) ;
173- let types = pluck ( fields. iter ( ) , |f| f. ty . clone ( ) ) ;
174- impl_compound ( ty, ty_generics, & index, & names, & types)
182+ if find_repr ( attrs, & [ "C" , "packed" , "transparent" ] ) . expect (
183+ "H5Type requires repr(C), repr(packed) or repr(transparent) for tuple structs" ,
184+ ) == "transparent"
185+ {
186+ assert_eq ! ( fields. len( ) , 1 ) ;
187+ impl_transparent ( & fields[ 0 ] . ty )
188+ } else {
189+ let names = ( 0 ..fields. len ( ) ) . map ( |f| f. to_string ( ) ) . collect :: < Vec < _ > > ( ) ;
190+ let types = pluck ( fields. iter ( ) , |f| f. ty . clone ( ) ) ;
191+ impl_compound ( ty, ty_generics, & index, & names, & types)
192+ }
175193 }
176194 } ,
177195 Data :: Enum ( ref data) => {
0 commit comments