I created a small Wasm file from this Rust code:
#[no_mangle]
pub fn hello() -> &\'static str {
\"hello from rust\"
}
It builds
You cannot directly return a Rust String or an &str. Instead allocate and return a raw byte pointer containing the data which has to be then encoded as a JS string on the JavaScript side.
You can take a look at the SHA1 example here.
The functions of interest are in
demos/bundle.js - copyCStrdemos/sha1/sha1-digest.rs - digestFor more examples: https://www.hellorust.com/demos/sha1/index.html