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"