首页 > 解决方案 > 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",
]

在此处输入图像描述

标签: rustrust-analyzer

解决方案


推荐阅读