ferrosaur

Crates.ioferrosaur
lib.rsferrosaur
version0.1.1
created_at2025-05-07 17:04:13.33312+00
updated_at2025-05-09 19:36:31.604503+00
descriptionStatic codegen for deno_core. 🦀📲🦕
homepagehttps://tonywu6.github.io/ferrosaur/
repositoryhttps://github.com/tonywu6/ferrosaur
max_upload_size
id1664119
size191,014
tonywu6 (tonywu6)

documentation

README

ferrosaur

crates.io documentation MIT/Apache-2.0 licensed

ferrosaur derives statically-typed Rust code — à la wasm-bindgen — for deno_core::JsRuntime to interface with your JavaScript code.

If you have:

// lib.js
export const slowFib = (n) =>
  n === 0 ? 0 : n === 1 ? 1 : slowFib(n - 1) + slowFib(n - 2);

... and you write:

// lib.rs
use ferrosaur::js;

#[js(module("lib.js"))]
struct Math;

#[js(interface)]
impl Math {
    #[js(func)]
    fn slow_fib(&self, n: serde<usize>) -> serde<usize> {}
}

... then you get:

// let rt: &mut JsRuntime;
let lib = Math::main_module_init(rt).await?;
let fib = lib.slow_fib(42, rt)?;
assert_eq!(fib, 267914296);

[!TIP]

This is like the inverse of deno_core::op2:

  • #[op2] gives JavaScript programs easy access to your Rust implementation.
  • ferrosaur gives your Rust program easy access to JavaScript implementations.

License

This project is released under the Apache 2.0 License and the MIT License.

Commit count: 70

cargo fmt