kataglyphis_rustprojecttemplate/api/
simple.rs

1#[flutter_rust_bridge::frb(sync)]
2pub fn greet(name: String) -> String {
3    format!("Hello, you {name}!")
4}
5
6#[cfg(not(target_arch = "wasm32"))]
7#[flutter_rust_bridge::frb(init)]
8pub fn init_app() {
9    // Default utilities - feel free to customize
10    flutter_rust_bridge::setup_default_user_utils();
11}
12
13#[cfg(target_arch = "wasm32")]
14#[flutter_rust_bridge::frb(sync)]
15pub fn init_app() {
16    // Default utilities - feel free to customize
17    flutter_rust_bridge::setup_default_user_utils();
18}
19
20// ✅ Heavy computation - synchron für jetzt
21#[flutter_rust_bridge::frb(sync)]
22pub fn heavy_computation(input: i32) -> i32 {
23    // Einfache Berechnung
24    let mut result = input;
25    for _ in 0..1000 {
26        result = (result * 2) % 1000000;
27    }
28    result
29}
30
31// ✅ Mit echter Async (nur für Non-WASM)
32#[cfg(not(target_family = "wasm"))]
33#[flutter_rust_bridge::frb()]
34pub async fn async_heavy_work(input: i32) -> i32 {
35    tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;
36    input * 2
37}
38
39// ✅ Mit echter Async (WASM-kompatibel)
40#[cfg(target_family = "wasm")]
41#[flutter_rust_bridge::frb()]
42pub async fn async_heavy_work(input: i32) -> i32 {
43    tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;
44    input * 2
45}