actix_tls/connect/
connection.rs

1use super::Host;
2
3/// Wraps underlying I/O and the connection request that initiated it.
4#[derive(Debug)]
5pub struct Connection<R, IO> {
6    pub(crate) req: R,
7    pub(crate) io: IO,
8}
9
10impl_more::impl_deref_and_mut!(<R, IO> in Connection<R, IO> => io: IO);
11
12impl<R, IO> Connection<R, IO> {
13    /// Construct new `Connection` from request and IO parts.
14    pub fn new(req: R, io: IO) -> Self {
15        Self { req, io }
16    }
17}
18
19impl<R, IO> Connection<R, IO> {
20    /// Deconstructs into IO and request parts.
21    pub fn into_parts(self) -> (IO, R) {
22        (self.io, self.req)
23    }
24
25    /// Replaces underlying IO, returning old IO and new `Connection`.
26    pub fn replace_io<IO2>(self, io: IO2) -> (IO, Connection<R, IO2>) {
27        (self.io, Connection { io, req: self.req })
28    }
29
30    /// Returns a shared reference to the underlying IO.
31    pub fn io_ref(&self) -> &IO {
32        &self.io
33    }
34
35    /// Returns a mutable reference to the underlying IO.
36    pub fn io_mut(&mut self) -> &mut IO {
37        &mut self.io
38    }
39
40    /// Returns a reference to the connection request.
41    pub fn request(&self) -> &R {
42        &self.req
43    }
44}
45
46impl<R: Host, IO> Connection<R, IO> {
47    /// Returns hostname.
48    pub fn hostname(&self) -> &str {
49        self.req.hostname()
50    }
51}