kataglyphis_rustprojecttemplate/api/
simple.rs1#[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 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 flutter_rust_bridge::setup_default_user_utils();
18}
19
20#[flutter_rust_bridge::frb(sync)]
22pub fn heavy_computation(input: i32) -> i32 {
23 let mut result = input;
25 for _ in 0..1000 {
26 result = (result * 2) % 1000000;
27 }
28 result
29}
30
31#[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#[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}