fidl_next_bind/
fuchsia.rs1use fuchsia_async::Task;
8use zx::Channel;
9
10use fidl_next_protocol::Transport;
11
12use crate::{
13 Client, ClientEnd, ClientProtocol, ClientSender, Server, ServerEnd, ServerProtocol,
14 ServerSender,
15};
16
17pub fn create_channel<P>() -> (ClientEnd<zx::Channel, P>, ServerEnd<zx::Channel, P>) {
19 let (client_end, server_end) = Channel::create();
20 (ClientEnd::from_untyped(client_end), ServerEnd::from_untyped(server_end))
21}
22
23pub fn spawn_client_detached<T, P, H>(client_end: ClientEnd<T, P>, handler: H) -> ClientSender<T, P>
30where
31 T: Transport + 'static,
32 P: ClientProtocol<T, H> + 'static,
33 H: Send + 'static,
34{
35 let mut client = Client::new(client_end);
36 let sender = client.sender().clone();
37 Task::spawn(async move { client.run(handler).await }).detach_on_drop();
38 sender
39}
40
41pub fn spawn_client_sender_detached<T, P>(client_end: ClientEnd<T, P>) -> ClientSender<T, P>
48where
49 T: Transport + 'static,
50 P: 'static,
51{
52 let mut client = Client::new(client_end);
53 let sender = client.sender().clone();
54 Task::spawn(async move { client.run_sender().await }).detach_on_drop();
55 sender
56}
57
58pub fn spawn_server_detached<T, P, H>(server_end: ServerEnd<T, P>, handler: H) -> ServerSender<T, P>
65where
66 T: Transport + 'static,
67 P: ServerProtocol<T, H> + 'static,
68 H: Send + 'static,
69{
70 let mut server = Server::new(server_end);
71 let sender = server.sender().clone();
72 Task::spawn(async move { server.run(handler).await }).detach_on_drop();
73 sender
74}