Is it possible to write a function that works along the lines of:
enum ProtAddr {
Tcp(String),
#[cfg(unix)]
Uds(PathBuf)
}
pub fn connect<T>(pa: ProtAddr) -> Result<Framed<T, MyCodec>, Error> {
match pa {
ProtAddr::Tcp(sa) => {
let stream = TcpStream::connect(sa).await?;
let framed = Framed::new(stream, MyCodec::new());
}
#[cfg(unix)]
ProtAddr::Uds(sa) => {
let stream = UnixStream::connect(sa).await?;
let framed = Framed::new(stream, MyCodec::new());
}
}
}
Having the protocol determined at runtime, but the return time generic at compile time feels like a no-no.