use async_trait::async_trait;
use tokio::net::UnixStream;
use crate::asnc::io::{Connection, ConnectionBuilder, ConnectionHandler};
use crate::asnc::marker::AsyncConnConf;
use crate::core::io::ChannelDetails;
use crate::core::utils::SharedCloser;
use crate::prelude::*;
#[async_trait]
impl<V: MaybeVersioned> ConnectionBuilder<V> for SockClient {
async fn build(&self) -> Result<(Connection<V>, ConnectionHandler)> {
let path = self.path.clone();
let stream = UnixStream::connect(path.as_path()).await?;
let (reader, writer) = stream.into_split();
let (connection, chan_factory) = Connection::new(self.info.clone(), SharedCloser::new());
let chan_info = connection
.info()
.make_channel_info(ChannelDetails::SockClient { path });
let channel = chan_factory.build(chan_info, reader, writer);
let channel_state = channel.spawn().await;
let handler = ConnectionHandler::spawn_from_state(channel_state);
Ok((connection, handler))
}
fn to_conf(&self) -> AsyncConnConf<V> {
AsyncConnConf::new(self.clone())
}
fn is_repairable(&self) -> bool {
true
}
}