mirror of
https://github.com/OpenCut-app/OpenCut.git
synced 2026-07-13 21:52:53 +02:00
feat: add shared Rust crates for cross-platform time utilities
Introduce `bridge` proc-macro crate with `#[export]` attribute that conditionally applies `wasm_bindgen` for WASM builds, and `time` crate porting all timecode/frame utilities from TypeScript to Rust.
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
# rust/
|
||||
|
||||
Shared Rust crates that power OpenCut across platforms (web via WASM, desktop natively).
|
||||
|
||||
## Adding a new crate
|
||||
|
||||
1. Create it under `rust/crates/`
|
||||
2. Add `bridge` as a dependency
|
||||
3. Annotate public functions with `#[export]`
|
||||
|
||||
## How `#[export]` works
|
||||
|
||||
```rust
|
||||
use bridge::export;
|
||||
|
||||
#[export]
|
||||
pub fn round_to_frame(time: f64, fps: f64) -> f64 {
|
||||
(time * fps).round() / fps
|
||||
}
|
||||
```
|
||||
|
||||
Without the `wasm` feature, the macro is a no-op. With `--features wasm`, it expands to:
|
||||
|
||||
```rust
|
||||
#[wasm_bindgen(js_name = "roundToFrame")]
|
||||
pub fn round_to_frame(time: f64, fps: f64) -> f64 { ... }
|
||||
```
|
||||
|
||||
Desktop uses the crates directly as Cargo dependencies.
|
||||
|
||||
## Testing
|
||||
|
||||
```bash
|
||||
cargo test -p <crate>
|
||||
```
|
||||
Reference in New Issue
Block a user