1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
pub mod conn;
use std::io::Error as IoError;
use async_std::net::ToSocketAddrs;
use super::proto::{
transport::{MessageTransport, MessageTransportError},
message::Message
};
use conn::Connection;
pub struct Client {
conn: MessageTransport<Connection>,
}
impl Client {
pub async fn new<A: ToSocketAddrs>(addrs: A) -> Result<Client, IoError> {
Ok(Client {
conn: MessageTransport::new(Connection::unsecure(addrs).await?),
})
}
pub async fn read_message(&mut self) -> Result<Message, MessageTransportError> {
self.conn.read_message().await
}
pub async fn write_message(&mut self, m: Message) -> Result<(), MessageTransportError> {
self.conn.write_message(m).await
}
}