hippofish/packages/backend-rs
2024-07-15 20:05:42 +00:00
..
src chore (backend-rs): do not use Arc for internal actor caches at least for now 2024-07-13 22:43:05 +09:00
.gitignore meta: backend/native-utils -> backend-rs 2024-02-12 23:14:23 +09:00
build.rs chore (backend-rs): update build script 2024-06-06 17:10:41 +09:00
Cargo.toml meta (backend-rs, macro-rs): set Rust version and edition in root 2024-07-09 18:36:45 +09:00
index.d.ts refactor (backend): port getInstanceActor/getRelayActor to backend-rs 2024-07-13 20:45:52 +09:00
index.js refactor (backend): port getInstanceActor/getRelayActor to backend-rs 2024-07-13 20:45:52 +09:00
Makefile chore (backend-rs): use custom macros 2024-07-03 16:32:12 +09:00
package.json chore(deps): update dependency @napi-rs/cli to v3.0.0-alpha.59 2024-07-15 20:05:42 +00:00
README.md docs (backend-rs): minor updates 2024-07-06 02:04:24 +09:00

A work-in-progress Firefish backend written in Rust

Minimum supported Rust version (MSRV): 1.74

Auto-generated documentation is at https://docs.firefish.dev/backend_rs

How to write the code

Currently, there is no entrypoint in this project, and all functions are executed via Node-API.

You need to apply the [macros::export] proc macro to export a function to the Node.js backend:

#[macros::export]
pub fn to_be_exported(value: &str) -> i32 {
    // You can also call other functions that are not exported
    do_something();
    42
}

fn do_something() {
    do_other_thing();
}

this code will be translated into this TypeScript code:

export declare function toBeExported(value: string): number {
    /* executes the compiled Rust function */
}

You can also export async functions:

#[macros::export]
pub async fn async_function() -> i32 {
    some_async_task().await
}
export declare function asyncFunction(): Promise<number> {
    /* executes the compiled Rust function */
}

You need to specify object attribute to export structs:

#[macros::export(object)]
pub struct Thing {
    pub field_one: String,
    pub field_two: Option<String>,
}
export interface Thing {
    fieldOne: string
    fieldTwo: string | null
}

Update auto-generated files

These files are auto-generated and are not intended for manual editing:

Prerequisites

  1. dev/config.env (see dev/config.example.env for reference)
  2. PostgreSQL database listening on port 25432
  3. Dev dependencies

Update database entity

Run the following command in the repository root directory

make entities

Update index.js and index.d.ts

Run the following command in the repository root directory

make napi

Unit tests

It is highly encouraged that you write unit tests and test the code yourself (there is no integration test at this point).

Prerequisites

  1. dev/config.env (see dev/config.example.env for reference)
  2. Firefish config file (.config/default.yml)
  3. Dev dependency

Run unit tests

Run the following command in the repository root directory

pnpm run test:rs