@@ -413,7 +413,7 @@ impl Parse for AnyIdent {
413
413
///
414
414
/// Used to convert syn tokens into an AST, that we can then use to generate glue code. The context
415
415
/// (`Ctx`) is used to pass in the attributes from the `#[wasm_bindgen]`, if needed.
416
- trait ConvertToAst < Ctx > {
416
+ pub ( crate ) trait ConvertToAst < Ctx > {
417
417
/// What we are converting to.
418
418
type Target ;
419
419
/// Convert into our target.
@@ -422,27 +422,27 @@ trait ConvertToAst<Ctx> {
422
422
fn convert ( self , context : Ctx ) -> Result < Self :: Target , Diagnostic > ;
423
423
}
424
424
425
- impl ConvertToAst < ( & ast:: Program , BindgenAttrs ) > for & mut syn:: ItemStruct {
425
+ impl ConvertToAst < & ast:: Program > for & mut syn:: ItemStruct {
426
426
type Target = ast:: Struct ;
427
427
428
- fn convert (
429
- self ,
430
- ( program, attrs) : ( & ast:: Program , BindgenAttrs ) ,
431
- ) -> Result < Self :: Target , Diagnostic > {
428
+ fn convert ( self , program : & ast:: Program ) -> Result < Self :: Target , Diagnostic > {
432
429
if !self . generics . params . is_empty ( ) {
433
430
bail_span ! (
434
431
self . generics,
435
432
"structs with #[wasm_bindgen] cannot have lifetime or \
436
433
type parameters currently"
437
434
) ;
438
435
}
436
+ let struct_attrs = BindgenAttrs :: find ( & mut self . attrs ) ?;
437
+
439
438
let mut fields = Vec :: new ( ) ;
440
- let js_name = attrs
439
+ let js_name = struct_attrs
441
440
. js_name ( )
442
441
. map ( |s| s. 0 . to_string ( ) )
443
442
. unwrap_or ( self . ident . unraw ( ) . to_string ( ) ) ;
444
- let is_inspectable = attrs. inspectable ( ) . is_some ( ) ;
445
- let getter_with_clone = attrs. getter_with_clone ( ) ;
443
+ let is_inspectable = struct_attrs. inspectable ( ) . is_some ( ) ;
444
+ let getter_with_clone = struct_attrs. getter_with_clone ( ) ;
445
+
446
446
for ( i, field) in self . fields . iter_mut ( ) . enumerate ( ) {
447
447
match field. vis {
448
448
syn:: Visibility :: Public ( ..) => { }
@@ -484,9 +484,9 @@ impl ConvertToAst<(&ast::Program, BindgenAttrs)> for &mut syn::ItemStruct {
484
484
} ) ;
485
485
attrs. check_used ( ) ;
486
486
}
487
- let generate_typescript = attrs . skip_typescript ( ) . is_none ( ) ;
487
+ let generate_typescript = struct_attrs . skip_typescript ( ) . is_none ( ) ;
488
488
let comments: Vec < String > = extract_doc_comments ( & self . attrs ) ;
489
- attrs . check_used ( ) ;
489
+ struct_attrs . check_used ( ) ;
490
490
Ok ( ast:: Struct {
491
491
rust_name : self . ident . clone ( ) ,
492
492
js_name,
@@ -1159,11 +1159,6 @@ impl<'a> MacroParse<(Option<BindgenAttrs>, &'a mut TokenStream)> for syn::Item {
1159
1159
wasm_bindgen_futures : program. wasm_bindgen_futures . clone ( ) ,
1160
1160
} ) ;
1161
1161
}
1162
- syn:: Item :: Struct ( mut s) => {
1163
- let opts = opts. unwrap_or_default ( ) ;
1164
- program. structs . push ( ( & mut s) . convert ( ( program, opts) ) ?) ;
1165
- s. to_tokens ( tokens) ;
1166
- }
1167
1162
syn:: Item :: Impl ( mut i) => {
1168
1163
let opts = opts. unwrap_or_default ( ) ;
1169
1164
( & mut i) . macro_parse ( program, opts) ?;
0 commit comments