Skip to content

Tutorial

In this tutorial, we will build a cross-language Calculator library.

Terminal window
bridge new calculator
cd calculator

We will create a specific Calculator struct.

use bridgerust::prelude::*;
#[bridge]
struct Calculator {
value: f64
}
#[bridge_methods]
impl Calculator {
#[constructor]
fn new() -> Self {
Self { value: 0.0 }
}
#[method]
fn add(&mut self, val: f64) {
self.value += val;
}
#[method]
fn result(&self) -> f64 {
self.value
}
}
from calculator import Calculator
c = Calculator()
c.add(10.0)
print(c.result())
import { Calculator } from "calculator";
const c = new Calculator();
c.add(10.0);
console.log(c.result());