use super::Host; use crate::impl_more; /// Wraps underlying I/O and the connection request that initiated it. #[derive(Debug)] pub struct Connection { pub(crate) req: R, pub(crate) io: IO, } impl_more::deref! { Connection => io: IO } impl_more::deref_mut! { Connection => io } impl Connection { /// Construct new `Connection` from request and IO parts. pub fn new(req: R, io: IO) -> Self { Self { req, io } } } impl Connection { /// Deconstructs into IO and request parts. pub fn into_parts(self) -> (IO, R) { (self.io, self.req) } /// Replaces underlying IO, returning old IO and new `Connection`. pub fn replace_io(self, io: IO2) -> (IO, Connection) { (self.io, Connection { io, req: self.req }) } /// Returns a shared reference to the underlying IO. pub fn io_ref(&self) -> &IO { &self.io } /// Returns a mutable reference to the underlying IO. pub fn io_mut(&mut self) -> &mut IO { &mut self.io } /// Returns a reference to the connection request. pub fn request(&self) -> &R { &self.req } } impl Connection { /// Returns hostname. pub fn hostname(&self) -> &str { self.req.hostname() } }