-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #193 from tauri-apps/feat/async
Feat: async host functions
- Loading branch information
Showing
63 changed files
with
4,291 additions
and
1,218 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#[allow(unused_imports, unused_variables, dead_code)] | ||
#[rustfmt::skip] | ||
pub mod chars { | ||
use ::tauri_bindgen_host::serde; | ||
use ::tauri_bindgen_host::bitflags; | ||
#[::tauri_bindgen_host::async_trait] | ||
pub trait Chars: Sized { | ||
///A function that accepts a character | ||
async fn take_char(&self, x: char); | ||
///A function that returns a character | ||
async fn return_char(&self) -> char; | ||
} | ||
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: Chars + 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( | ||
"chars", | ||
"take_char", | ||
move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller<T>, p: char| { | ||
let get_cx = get_cx.clone(); | ||
Box::pin(async move { | ||
let ctx = get_cx(ctx.data()); | ||
Ok(ctx.take_char(p).await) | ||
}) | ||
}, | ||
)?; | ||
let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); | ||
router | ||
.define_async( | ||
"chars", | ||
"return_char", | ||
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.return_char().await) | ||
}) | ||
}, | ||
)?; | ||
Ok(()) | ||
} | ||
} |
Oops, something went wrong.