从板条箱stdweb使用#[JS_EXPORT]时会出现错误

发布于 2025-01-28 03:38:50 字数 1947 浏览 2 评论 0原文

我需要在Rust-Wasm程序中读取客户端文件,并且我正在尝试使用Stackoverflow上的两个解决方案 and https://stackoverflow.com/a/a/a/69305956/444666255 。这两种解决方案均被接受并给予赏金,因此我假设它们起作用。

这两者都使用了以下代码,

use stdweb::js_export
#[js_export]

但是当我尝试编译这些代码时,我会遵循

error[E0425]: cannot find function `__web_free` in module `stdweb::private`
  --> src/lib.rs:14:1
   |
14 | #[js_export]
   | ^^^^^^^^^^^^ not found in `stdweb::private`
   |
   = note: this error originates in the attribute macro `js_export` (in Nightly builds, run with -Z macro-backtrace for more info)

错误的错误。我们如何使它起作用?

我从Stackoverflow https://stackoverflow.com/a/51231915

#[macro_use]
extern crate stdweb;

use stdweb::js_export;
use stdweb::web::FileReader;
use stdweb::web::FileReaderResult;

#[js_export]
fn print_result(file_reader: FileReader) -> String {
    match file_reader.result() {
        Some(value) => match value {
            FileReaderResult::String(value) => value,
            _ => String::from("not a text"),
        }
        None => String::from("empty")
    }
}

pub fn test_reader() {
    stdweb::initialize();

    stdweb::event_loop();
}

cargo.toml文件是

[package]
name = "read-file2"
version = "0.1.0"
authors = ["kushdesh"]
edition = "2018"

[lib]
crate-type = ["cdylib", "rlib"]

[features]
default = ["console_error_panic_hook"]

[dependencies]
wasm-bindgen = "0.2.63"
stdweb = "0.4.20"

console_error_panic_hook = { version = "0.1.6", optional = true }

wee_alloc = { version = "0.4.5", optional = true }

[dev-dependencies]
wasm-bindgen-test = "0.3.13"

[profile.release]
# Tell `rustc` to optimize for small code size.
opt-level = "s"

I need to read client file in a rust-wasm program and I am trying two solution given on stackoverflow https://stackoverflow.com/a/51231915 and https://stackoverflow.com/a/69305956/4466255. Both these solutions are accepted and given bounties so I am assuming they work.

both of these have used following code

use stdweb::js_export
#[js_export]

But when i try to compile these codes I got following error

error[E0425]: cannot find function `__web_free` in module `stdweb::private`
  --> src/lib.rs:14:1
   |
14 | #[js_export]
   | ^^^^^^^^^^^^ not found in `stdweb::private`
   |
   = note: this error originates in the attribute macro `js_export` (in Nightly builds, run with -Z macro-backtrace for more info)

What I am missing. How can we make it work?

My current code, which I have taken from stackoverflow https://stackoverflow.com/a/51231915, in lib.rs is

#[macro_use]
extern crate stdweb;

use stdweb::js_export;
use stdweb::web::FileReader;
use stdweb::web::FileReaderResult;

#[js_export]
fn print_result(file_reader: FileReader) -> String {
    match file_reader.result() {
        Some(value) => match value {
            FileReaderResult::String(value) => value,
            _ => String::from("not a text"),
        }
        None => String::from("empty")
    }
}

pub fn test_reader() {
    stdweb::initialize();

    stdweb::event_loop();
}

and the Cargo.toml file is

[package]
name = "read-file2"
version = "0.1.0"
authors = ["kushdesh"]
edition = "2018"

[lib]
crate-type = ["cdylib", "rlib"]

[features]
default = ["console_error_panic_hook"]

[dependencies]
wasm-bindgen = "0.2.63"
stdweb = "0.4.20"

console_error_panic_hook = { version = "0.1.6", optional = true }

wee_alloc = { version = "0.4.5", optional = true }

[dev-dependencies]
wasm-bindgen-test = "0.3.13"

[profile.release]
# Tell `rustc` to optimize for small code size.
opt-level = "s"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文