rust - 使用 web_sys::HtmlButtonElement 失败

标签 rust webassembly wasm-bindgen wasm-pack

这个问题在这里已经有了答案:





How do you enable a Rust "crate feature"?

(1 个回答)


2年前关闭。




设法构建和运行 https://github.com/rustwasm/wasm-bindgen/tree/master/examples 中的一些示例

然后从用于 Dom 操作的小原型(prototype)程序开始,一切正常,直到卡在这个问题上。

采用
https://docs.rs/web-sys/0.3.35/web_sys/struct.HtmlButtonElement.html

列表 pub struct HtmlButtonElement , 如同

https://docs.rs/web-sys/0.3.35/web_sys/struct.Element.html
https://docs.rs/web-sys/0.3.35/web_sys/struct.HtmlElement.html

有:

use web_sys::Element;
use web_sys::HtmlElement;
use web_sys::HtmlButtonElement;

给出编译错误:
error[E0432]: unresolved import `web_sys::HtmlButtonElement`
 --> src/lib.rs:8:5
  |
8 | use web_sys::HtmlButtonElement;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^ no `HtmlButtonElement` in the root

ElementHtmlElement可在 web_sys 中找到
HtmlButtonElement 的区别/缺失是什么? ? no HtmlButtonElement in the root留言给个提示?

最佳答案

在@chpio 发表评论之后。添加时 HtmlButtonElement Cargo.toml 中的功能 HtmlButtonElement建的时候发现。

关于rust - 使用 web_sys::HtmlButtonElement 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59667434/

相关文章:

multithreading - 向量中函数的线程调用

promise - Rust/Webassembly/wasm-bindgen - 从 `js_sys' Promise 获取值

uwp - Uno Platform - WASM - 有没有办法读取浏览器的地址栏/与之交互?

rust - 使用了函数 `print` 但为什么它警告我 `unused` ?

rust - 什么是元组变体? (了解编译器错误信息)

rust - 在返回位置使用通用关联类型的 Impl trait 会导致生命周期错误

struct - 如何为字段值为另一个结构的结构实现 rustc_serialize::Decodable?

arrays - 从 rust 中从数组转换的字符串中删除多余的长度

javascript - emscripten - 如何从 JavaScript (Chrome/Firefox) 读取 C 数组?

rust - 如何通过 WebAssembly 将 Rust 闭包返回给 JavaScript?