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
35
36
37
38
39
40
41
42
43
44
45
46
use std::io;
use std::net::SocketAddr;
use futures::{Future, Sink, Stream};
use tokio::net::TcpStream;
use tokio_io::AsyncRead;
use error;
use resp;
pub fn connect(
addr: &SocketAddr,
) -> Box<Future<Item = ClientConnection, Error = io::Error> + Send> {
let con = TcpStream::connect(addr).map(move |socket| {
let framed = socket.framed(resp::RespCodec);
let (write_f, read_f) = framed.split();
ClientConnection {
sender: Box::new(write_f),
receiver: Box::new(read_f),
}
});
Box::new(con)
}
pub struct ClientConnection {
pub sender: Box<Sink<SinkItem = resp::RespValue, SinkError = io::Error> + Send>,
pub receiver: Box<Stream<Item = resp::RespValue, Error = error::Error> + Send>,
}