简单地添加console_error_panic_hook::set_once()
会导致错误:
[WARN]: :-) origin crate has no README
[INFO]: Installing wasm-bindgen...
error: cannot shadow already defined class `Error`
Error: Running the wasm-bindgen CLI
Caused by: failed to execute `wasm-bindgen`: exited with exit code: 1
是的,我确实有自己的Error
结构,但为什么使用这个函数会导致“影子”错误?
仅当我Error
使用[wasm_bindgen]
.
运行后出现错误wasm-pack build --target web
再生产
# cargo.toml
[package]
name = "testing"
version = "0.1.0"
edition = "2021"
[lib]
crate-type = ["cdylib", "rlib"]
[dependencies]
console_error_panic_hook = "0.1.7"
wasm-bindgen = { version = "0.2.76" }
// lib.rs
use wasm_bindgen::prelude::wasm_bindgen;
// Adding this does not help:
// extern crate console_error_panic_hook;
#[wasm_bindgen] // Works if either this line is remove...
struct Error {}
#[wasm_bindgen]
pub fn main() {
console_error_panic_hook::set_once(); // ... or this one
println!("Hello, world!");
}
版本
wasm-pack 0.10.2
cargo 1.58.0 (f01b232bc 2022-01-19)
rustc 1.58.1 (db9d1b20b 2022-01-20)