pub async fn demo<P, Server, ServerFuture, ServerResult, Client, ClientFuture, ClientResult>(
    server: &'static Server,
    client: &'static Client,
    max_length: usize,
) where
    P: Session,
    P::Dual: Session,
    Server: Fn(TcpChan<P>) -> ServerFuture + Sync + 'static,
    Client: Fn(BufReader<Stdin>, Stdout, TcpChan<P::Dual>) -> ClientFuture + Sync + 'static,
    ServerFuture:
        Future<Output = Result<ServerResult, Box<dyn Error>>> + std::marker::Send + 'static,
    ClientFuture:
        Future<Output = Result<ClientResult, Box<dyn Error>>> + std::marker::Send + 'static,
    ServerResult: Debug,
    ClientResult: Debug,
{
    use Party::*;
    let options = TcpAppOptions::from_args();
    if let Err(e) = match options.party {
        Server { port, ref address } => {
            listen_on::<P, _, _, _>(address, port, max_length, server).await
        }
        Client { port, ref address } => {
            connect_to::<P::Dual, _, _, _>(address, port, max_length, client).await
        }
    } {
        let party_name = match options.party {
            Server { .. } => "server",
            Client { .. } => "client",
        };
        eprintln!("{}", format!("[{}] Error: {}", party_name, e).red());
        process::exit(1);
    }
}
/// Given client and server functions for a given session type `P`, construct a simple app that
/// behaves as either a client or a server, depending on its command line arguments, and
/// communicates over TCP.
Given client and server functions for a given session type `P`, construct a simple app that
behaves as either a client or a server, depending on its command line arguments, and
communicates over TCP.
Given client and server functions for a given session type ` P ` construct a simple app that behaves as either a client or a server depending on its command line arguments and communicates over TCP .
pub async fn demo<P, Server, ServerFuture, ServerResult, Client, ClientFuture, ClientResult>(
    server: &'static Server,
    client: &'static Client,
    max_length: usize,
) where
    P: Session,
    P::Dual: Session,
    Server: Fn(TcpChan<P>) -> ServerFuture + Sync + 'static,
    Client: Fn(BufReader<Stdin>, Stdout, TcpChan<P::Dual>) -> ClientFuture + Sync + 'static,
    ServerFuture:
        Future<Output = Result<ServerResult, Box<dyn Error>>> + std::marker::Send + 'static,
    ClientFuture:
        Future<Output = Result<ClientResult, Box<dyn Error>>> + std::marker::Send + 'static,
    ServerResult: Debug,
    ClientResult: Debug,
{
    use Party::*;
    let options = TcpAppOptions::from_args();
    if let Err(e) = match options.party {
        Server { port, ref address } => {
            listen_on::<P, _, _, _>(address, port, max_length, server).await
        }
        Client { port, ref address } => {
            connect_to::<P::Dual, _, _, _>(address, port, max_length, client).await
        }
    } {
        let party_name = match options.party {
            Server { .. } => "server",
            Client { .. } => "client",
        };
        eprintln!("{}", format!("[{}] Error: {}", party_name, e).red());
        process::exit(1);
    }
}
pub async fn demo < P , Server , ServerFuture , ServerResult , Client , ClientFuture , ClientResult > ( server : & ' static Server , client : & ' static Client , max_length : usize , ) where P : Session , P :: Dual : Session , Server : Fn ( TcpChan < P > ) -> ServerFuture + Sync + ' static , Client : Fn ( BufReader < Stdin > , Stdout , TcpChan < P :: Dual > ) -> ClientFuture + Sync + ' static , ServerFuture : Future < Output = Result < ServerResult , Box < dyn Error > > > + std :: marker :: Send + ' static , ClientFuture : Future < Output = Result < ClientResult , Box < dyn Error > > > + std :: marker :: Send + ' static , ServerResult : Debug , ClientResult : Debug , { use Party :: * ; let options = TcpAppOptions :: from_args ( ) ; if let Err ( e ) = match options . party { Server { port , ref address } => { listen_on :: < P , _ , _ , _ > ( address , port , max_length , server ) . await } Client { port , ref address } => { connect_to :: < P :: Dual , _ , _ , _ > ( address , port , max_length , client ) . await } } { let party_name = match options . party { Server { .. } => " " , Client { .. } => " " , } ; eprintln ! ( " " format ( " " party_name e ) red ( ) ) ; process :: exit ( 1 ) ; } }
Given client and server functions for a given session type `P`, construct a simple app that
behaves as either a client or a server, depending on its command line arguments, and
communicates over TCP.
Given client and server functions for a given session type ` P ` construct a simple app that behaves as either a client or a server depending on its command line arguments and communicates over TCP .
server
&'static Server
client
&'static Client
max_length
usize