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
use crate::error::{ClientErrorKind, Error, Result};
use std::io::{Read, Write};
use std::time::Duration;
use url::Url;
pub mod unix_socket;
pub const DEFAULT_TIMEOUT: Duration = Duration::from_secs(60);
pub trait ReadWrite: Read + Write {}
impl<T: Read + Write> ReadWrite for T {}
pub trait Connect {
fn connect(&self) -> Result<Box<dyn ReadWrite>>;
fn set_timeout(&mut self, timeout: Option<Duration>);
}
pub fn connector_from_url(socket_url: Url) -> Result<Box<dyn Connect + Send + Sync>> {
match socket_url.scheme() {
"unix" => Ok(Box::from(unix_socket::Handler::new(
socket_url.path().into(),
Some(DEFAULT_TIMEOUT),
)?)),
_ => Err(Error::Client(ClientErrorKind::InvalidSocketUrl)),
}
}