#![warn(
clippy::complexity,
clippy::correctness,
clippy::style,
future_incompatible,
missing_debug_implementations,
missing_docs,
rust_2018_idioms,
rustdoc::all,
clippy::undocumented_unsafe_blocks
)]
use std::{
io::{Read, Write},
net::TcpStream,
os::unix::net::UnixStream,
};
pub mod client;
pub mod fs;
pub mod protocol;
pub mod server;
use protocol::{Format9p, Rdata, Rmessage};
impl From<(u16, Result<Rdata>)> for Rmessage {
fn from((tag, content): (u16, Result<Rdata>)) -> Self {
Rmessage {
tag,
content: content.unwrap_or_else(|ename| Rdata::Error { ename }),
}
}
}
pub type Result<T> = std::result::Result<T, String>;
pub trait Stream: Read + Write + Send + Sized + 'static {
fn try_clone(&self) -> Result<Self>;
fn reply(&mut self, tag: u16, resp: Result<Rdata>) {
let r: Rmessage = (tag, resp).into();
let _ = r.write_to(self);
}
}
impl Stream for UnixStream {
fn try_clone(&self) -> Result<Self> {
self.try_clone().map_err(|e| e.to_string())
}
}
impl Stream for TcpStream {
fn try_clone(&self) -> Result<Self> {
self.try_clone().map_err(|e| e.to_string())
}
}