The new method on JsString class takes a &str so we add a & before the name of the variable:
use neon::prelude::*;
use neon::register_module;
fn echo(mut cx: FunctionContext) -> JsResult<JsString> {
let my_str = cx.argument::<JsString>(0)?.value() as String;
Ok(JsString::new(&mut cx, my_str))
}
register_module!(mut m, {
m.export_function("echo", echo)?;
Ok(())
});
In javascript
const addon = require('../native')
console.log(addon.echo('abc')) // 'abc'