mirror of
https://github.com/tauri-apps/tauri-bindgen.git
synced 2026-01-31 00:45:21 +01:00
77 lines
2.8 KiB
Rust
77 lines
2.8 KiB
Rust
#[allow(unused_imports, unused_variables, dead_code)]
|
|
#[rustfmt::skip]
|
|
pub mod floats {
|
|
use ::tauri_bindgen_host::serde;
|
|
use ::tauri_bindgen_host::bitflags;
|
|
#[::tauri_bindgen_host::async_trait]
|
|
pub trait Floats: Sized {
|
|
async fn float32_param(&self, x: f32);
|
|
async fn float64_param(&self, x: f64);
|
|
async fn float32_result(&self) -> f32;
|
|
async fn float64_result(&self) -> f64;
|
|
}
|
|
pub fn add_to_router<T, U>(
|
|
router: &mut ::tauri_bindgen_host::ipc_router_wip::Router<T>,
|
|
get_cx: impl Fn(&T) -> &U + Send + Sync + 'static,
|
|
) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error>
|
|
where
|
|
T: Send + Sync + 'static,
|
|
U: Floats + Send + Sync + 'static,
|
|
{
|
|
let wrapped_get_cx = ::std::sync::Arc::new(get_cx);
|
|
let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx);
|
|
router
|
|
.define_async(
|
|
"floats",
|
|
"float32_param",
|
|
move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller<T>, p: f32| {
|
|
let get_cx = get_cx.clone();
|
|
Box::pin(async move {
|
|
let ctx = get_cx(ctx.data());
|
|
Ok(ctx.float32_param(p).await)
|
|
})
|
|
},
|
|
)?;
|
|
let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx);
|
|
router
|
|
.define_async(
|
|
"floats",
|
|
"float64_param",
|
|
move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller<T>, p: f64| {
|
|
let get_cx = get_cx.clone();
|
|
Box::pin(async move {
|
|
let ctx = get_cx(ctx.data());
|
|
Ok(ctx.float64_param(p).await)
|
|
})
|
|
},
|
|
)?;
|
|
let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx);
|
|
router
|
|
.define_async(
|
|
"floats",
|
|
"float32_result",
|
|
move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller<T>, p: ()| {
|
|
let get_cx = get_cx.clone();
|
|
Box::pin(async move {
|
|
let ctx = get_cx(ctx.data());
|
|
Ok(ctx.float32_result().await)
|
|
})
|
|
},
|
|
)?;
|
|
let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx);
|
|
router
|
|
.define_async(
|
|
"floats",
|
|
"float64_result",
|
|
move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller<T>, p: ()| {
|
|
let get_cx = get_cx.clone();
|
|
Box::pin(async move {
|
|
let ctx = get_cx(ctx.data());
|
|
Ok(ctx.float64_result().await)
|
|
})
|
|
},
|
|
)?;
|
|
Ok(())
|
|
}
|
|
}
|