rust - Rust-analyzer web-sys 文档“未知”
问题描述
为什么是文档对象unknown
。事实上,一切,甚至window.document
调用都没有 linted。Linting 对我来说学习一种新的编程语言/库非常重要。
库文件
use wasm_bindgen::prelude::*;
#[wasm_bindgen(start)]
pub fn run() -> Result<(), JsValue> {
let window = web_sys::window().expect("could not get window handle");
let document = window.document().expect("could not get document handle");
let body = document.body().expect("could not get body handle");
let val = document.create_element("p")?;
val.set_text_content(Some("Hello from rust"));
body.append_child(&val)?;
Ok(())
}
货物.toml
[lib]
crate-type = ["cdylib"]
[dependencies]
serde = { version = "1.0", features = ["derive"] }
wasm-bindgen = { version = "0.2", features = ["serde-serialize"] }
[dependencies.web-sys]
version = "0.3.53"
features = [
"Document",
"Element",
"HtmlElement",
"Node",
"Window",
]
解决方案
推荐阅读
- go - 无法访问 Go Lambda 中的文件系统
- javascript - Postman 中函数体的 pm.sendRequest 不起作用
- java - 如何从另一种方法中访问字符串
- continuous-integration - 使用输出重定向到文件时,Gitlab CI 作业返回退出状态 1
- django - 处理请求的两种方式——只是写法不同
- django - 通过 Rancher 将 Django、Gunicorn docker 镜像部署到 Kubernetes 的问题
- ruby - RSpec 测试分叉过程
- angularjs - 无法从 Angularjs 中的文件加载部分视图
- c++ - 从文件 C++ 中查找标准差
- caching - Shopware 6:更改 URL 参数在 prod 模式下返回相同的结果