parcel-plugin-cargo-web icon indicating copy to clipboard operation
parcel-plugin-cargo-web copied to clipboard

Not able to return string

Open poovarasanvasudevan opened this issue 5 years ago • 0 comments

i am returning string from rust function, but not able to parse from javascript

lib.rs

#[js_export]
pub fn hello( string: &str ) -> String {
    "hello".into()
}

client js

import lib from './test/Cargo.toml'
console.log(lib.hello("hello")

Cargo.toml

[package]
name = "wasm"
version = "0.1.0"
authors = ["poovarasan <[email protected]>"]
edition = "2018"

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

[dependencies]
stdweb = "0.4.20"
serde_derive = "1.0.102"
serde = "1.0.102"
sha1 = "0.6.0"

error i got

Uncaught (in promise) RuntimeError: unreachable
    at __rust_start_panic (<anonymous>:wasm-function[62]:0x1415)
    at rust_panic (<anonymous>:wasm-function[61]:0x140d)
    at _ZN3std9panicking20rust_panic_with_hook17h123718ba3bf480afE (<anonymous>:wasm-function[56]:0x1159)
    at _ZN3std9panicking19begin_panic_handler28_$u7b$$u7b$closure$u7d$$u7d$17hf393a82e58397bd2E (<anonymous>:wasm-function[48]:0xede)
    at _ZN3std10sys_common9backtrace26__rust_end_short_backtrace17h2ff2cfc953878925E (<anonymous>:wasm-function[47]:0xe5f)
    at rust_begin_unwind (<anonymous>:wasm-function[55]:0x1051)
    at _ZN4core9panicking9panic_fmt17h285dc015a87be5a4E (<anonymous>:wasm-function[81]:0x4088)
    at _ZN4core9panicking5panic17h0abe4e7a620ae568E (<anonymous>:wasm-function[77]:0x3775)
    at _ZN151_$LT$stdweb..webcore..serialization..SerializedValue$u20$as$u20$core..convert..From$LT$stdweb..webcore..serialization..SerializedUntaggedString$GT$$GT$4from17h49d80c9b4bb65ef2E.llvm.6607008737656612370 (<anonymous>:wasm-function[2]:0x21b)
    at hello (<anonymous>:wasm-function[13]:0x70d)

image

Thanks

poovarasanvasudevan avatar Jan 04 '21 05:01 poovarasanvasudevan