1
1
#![ doc( html_root_url = "https://docs.rs/wasm-bindgen-cli-support/0.2" ) ]
2
2
3
- use failure :: { bail, Error , ResultExt } ;
3
+ use anyhow :: { bail, Context , Error } ;
4
4
use std:: collections:: { BTreeMap , BTreeSet , HashMap } ;
5
5
use std:: env;
6
6
use std:: fs;
@@ -256,7 +256,7 @@ impl Bindgen {
256
256
}
257
257
Input :: Path ( ref path) => {
258
258
let contents = fs:: read ( & path)
259
- . with_context ( |_ | format ! ( "failed to read `{}`" , path. display( ) ) ) ?;
259
+ . with_context ( || format ! ( "failed to read `{}`" , path. display( ) ) ) ?;
260
260
let module = walrus:: ModuleConfig :: new ( )
261
261
// Skip validation of the module as LLVM's output is
262
262
// generally already well-formed and so we won't gain much
@@ -307,7 +307,7 @@ impl Bindgen {
307
307
308
308
self . threads
309
309
. run ( & mut module)
310
- . with_context ( |_ | "failed to prepare module for threading" ) ?;
310
+ . with_context ( || "failed to prepare module for threading" ) ?;
311
311
312
312
// If requested, turn all mangled symbols into prettier unmangled
313
313
// symbols with the help of `rustc-demangle`.
@@ -373,10 +373,10 @@ impl Bindgen {
373
373
. context ( "failed to transform return pointers into multi-value Wasm" ) ?;
374
374
}
375
375
webidl:: standard:: add_section ( & mut module, & aux, & bindings)
376
- . with_context ( |_ | "failed to generate a standard wasm bindings custom section" ) ?;
376
+ . with_context ( || "failed to generate a standard wasm bindings custom section" ) ?;
377
377
} else {
378
378
if self . multi_value {
379
- failure :: bail!(
379
+ anyhow :: bail!(
380
380
"Wasm multi-value is currently only available when \
381
381
Wasm interface types is also enabled"
382
382
) ;
@@ -565,11 +565,11 @@ impl Output {
565
565
& self . module
566
566
}
567
567
568
- pub fn emit ( & self , out_dir : impl AsRef < Path > ) -> Result < ( ) , Error > {
568
+ pub fn emit ( & mut self , out_dir : impl AsRef < Path > ) -> Result < ( ) , Error > {
569
569
self . _emit ( out_dir. as_ref ( ) )
570
570
}
571
571
572
- fn _emit ( & self , out_dir : & Path ) -> Result < ( ) , Error > {
572
+ fn _emit ( & mut self , out_dir : & Path ) -> Result < ( ) , Error > {
573
573
let wasm_name = if self . wasm_interface_types {
574
574
self . stem . clone ( )
575
575
} else {
@@ -579,7 +579,7 @@ impl Output {
579
579
fs:: create_dir_all ( out_dir) ?;
580
580
let wasm_bytes = self . module . emit_wasm ( ) ;
581
581
fs:: write ( & wasm_path, wasm_bytes)
582
- . with_context ( |_ | format ! ( "failed to write `{}`" , wasm_path. display( ) ) ) ?;
582
+ . with_context ( || format ! ( "failed to write `{}`" , wasm_path. display( ) ) ) ?;
583
583
584
584
if self . wasm_interface_types {
585
585
return Ok ( ( ) ) ;
@@ -593,15 +593,15 @@ impl Output {
593
593
let path = out_dir. join ( "snippets" ) . join ( identifier) . join ( name) ;
594
594
fs:: create_dir_all ( path. parent ( ) . unwrap ( ) ) ?;
595
595
fs:: write ( & path, js)
596
- . with_context ( |_ | format ! ( "failed to write `{}`" , path. display( ) ) ) ?;
596
+ . with_context ( || format ! ( "failed to write `{}`" , path. display( ) ) ) ?;
597
597
}
598
598
}
599
599
600
600
for ( path, contents) in self . local_modules . iter ( ) {
601
601
let path = out_dir. join ( "snippets" ) . join ( path) ;
602
602
fs:: create_dir_all ( path. parent ( ) . unwrap ( ) ) ?;
603
603
fs:: write ( & path, contents)
604
- . with_context ( |_ | format ! ( "failed to write `{}`" , path. display( ) ) ) ?;
604
+ . with_context ( || format ! ( "failed to write `{}`" , path. display( ) ) ) ?;
605
605
}
606
606
607
607
if self . npm_dependencies . len ( ) > 0 {
@@ -623,26 +623,26 @@ impl Output {
623
623
} ;
624
624
let js_path = out_dir. join ( & self . stem ) . with_extension ( extension) ;
625
625
fs:: write ( & js_path, reset_indentation ( & self . js ) )
626
- . with_context ( |_ | format ! ( "failed to write `{}`" , js_path. display( ) ) ) ?;
626
+ . with_context ( || format ! ( "failed to write `{}`" , js_path. display( ) ) ) ?;
627
627
628
628
if self . typescript {
629
629
let ts_path = js_path. with_extension ( "d.ts" ) ;
630
630
fs:: write ( & ts_path, & self . ts )
631
- . with_context ( |_ | format ! ( "failed to write `{}`" , ts_path. display( ) ) ) ?;
631
+ . with_context ( || format ! ( "failed to write `{}`" , ts_path. display( ) ) ) ?;
632
632
}
633
633
634
634
if self . mode . nodejs ( ) {
635
635
let js_path = wasm_path. with_extension ( extension) ;
636
636
let shim = self . generate_node_wasm_import ( & self . module , & wasm_path) ;
637
637
fs:: write ( & js_path, shim)
638
- . with_context ( |_ | format ! ( "failed to write `{}`" , js_path. display( ) ) ) ?;
638
+ . with_context ( || format ! ( "failed to write `{}`" , js_path. display( ) ) ) ?;
639
639
}
640
640
641
641
if self . typescript {
642
642
let ts_path = wasm_path. with_extension ( "d.ts" ) ;
643
643
let ts = wasm2es6js:: typescript ( & self . module ) ?;
644
644
fs:: write ( & ts_path, ts)
645
- . with_context ( |_ | format ! ( "failed to write `{}`" , ts_path. display( ) ) ) ?;
645
+ . with_context ( || format ! ( "failed to write `{}`" , ts_path. display( ) ) ) ?;
646
646
}
647
647
648
648
Ok ( ( ) )
0 commit comments