Trait tcp_client::ClientFactory
source · pub trait ClientFactory<C: From<(TcpStream, AesCipher)>> {
// Required methods
fn get_identifier(&self) -> &'static str;
fn get_version(&self) -> &'static str;
// Provided method
fn connect<'life0, 'async_trait, A>(
&'life0 self,
addr: A
) -> Pin<Box<dyn Future<Output = Result<C, NetworkError>> + Send + 'async_trait>>
where A: 'async_trait + ToSocketAddrs + Send,
Self: Sync + 'async_trait,
'life0: 'async_trait { ... }
}
Expand description
The client factory to create clients.
§Example
use tcp_client::client_base::ClientBase;
use tcp_client::client_factory;
use tcp_client::ClientFactory;
use tcp_client::network::NetworkError;
client_factory!(MyClientFactory, MyClient, "MyTcpApplication");
impl MyClient {
// define your method here.
// example:
async fn my_method(&mut self) -> Result<(), NetworkError> {
self.check_func("my_method").await?;
// ...
Ok(())
}
}
#[tokio::main]
async fn main() {
let mut client = MyClientFactory.connect("127.0.0.1:1234").await.unwrap();
// use client.
// example:
client.my_method().await.unwrap();
}
Required Methods§
sourcefn get_identifier(&self) -> &'static str
fn get_identifier(&self) -> &'static str
Provided Methods§
Object Safety§
This trait is not object safe.