use crate::{ data::Map, manager::data::Destination, DistantMsg, DistantRequestData, DistantResponseData, }; use async_trait::async_trait; use distant_net::{AuthClient, Request, Response, TypedAsyncRead, TypedAsyncWrite}; use std::{future::Future, io}; pub type BoxedDistantWriter = Box>> + Send>; pub type BoxedDistantReader = Box>> + Send>; pub type BoxedDistantWriterReader = (BoxedDistantWriter, BoxedDistantReader); pub type BoxedLaunchHandler = Box; pub type BoxedConnectHandler = Box; /// Used to launch a server at the specified destination, returning some result as a vec of bytes #[async_trait] pub trait LaunchHandler: Send + Sync { async fn launch( &self, destination: &Destination, options: &Map, auth_client: &mut AuthClient, ) -> io::Result; } #[async_trait] impl LaunchHandler for F where F: for<'a> Fn(&'a Destination, &'a Map, &'a mut AuthClient) -> R + Send + Sync + 'static, R: Future> + Send + 'static, { async fn launch( &self, destination: &Destination, options: &Map, auth_client: &mut AuthClient, ) -> io::Result { self(destination, options, auth_client).await } } /// Used to connect to a destination, returning a connected reader and writer pair #[async_trait] pub trait ConnectHandler: Send + Sync { async fn connect( &self, destination: &Destination, options: &Map, auth_client: &mut AuthClient, ) -> io::Result; } #[async_trait] impl ConnectHandler for F where F: for<'a> Fn(&'a Destination, &'a Map, &'a mut AuthClient) -> R + Send + Sync + 'static, R: Future> + Send + 'static, { async fn connect( &self, destination: &Destination, options: &Map, auth_client: &mut AuthClient, ) -> io::Result { self(destination, options, auth_client).await } }