Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

134
Views
Rust referencing with js-sandbox

I am writing a calculator in rust that uses js-sandbox to allow user-scripting for custom functions in javascript

I have a function that takes a mutable reference to an i32 and returns an Option in case of error, I call it run_js

I want to create a variable js_out and pass the reference to run_js, and print it out to prove that the function ran properly

I also have a main.js file with the function fibonacci which I tested, and it works with nodejs

I am getting the error: `let *output = script.call("fibonacci", &arg)?; expected pattern``

main.rs

use js_sandbox::{Script, AnyError};


fn run_js(sname: &str, output: &mut i32) -> Result<(), AnyError> {
    let mut script = Script::from_file(sname).expect("File can be loaded");
    let arg = 6;
    let *output = script.call("fibonacci", &arg)?;
    Ok(())
}

fn main() -> Result<(), AnyError> {
    println!("SCalc version 0.1.0");

    let mut js_out: i32 = 0;

    run_js("src/main.js", &mut js_out)?;

    println!("output: {}", js_out);
    Ok(())
}

main.js

function fibonacci(length, startNums=[0, 1]) {
    for (var i = 1; i < length-1; i++) {
        startNums.push(startNums[i-1]+startNums[i]);
    }
    return startNums[startNums.length-1];
}

console.log(fibonacci(6));
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!