distant_net/server/ref/
tcp.rs1use std::future::Future;
2use std::net::IpAddr;
3use std::ops::{Deref, DerefMut};
4use std::pin::Pin;
5use std::task::{Context, Poll};
6
7use tokio::task::JoinError;
8
9use super::ServerRef;
10
11pub struct TcpServerRef {
13 pub(crate) addr: IpAddr,
14 pub(crate) port: u16,
15 pub(crate) inner: ServerRef,
16}
17
18impl TcpServerRef {
19 pub fn new(addr: IpAddr, port: u16, inner: ServerRef) -> Self {
20 Self { addr, port, inner }
21 }
22
23 pub fn ip_addr(&self) -> IpAddr {
25 self.addr
26 }
27
28 pub fn port(&self) -> u16 {
30 self.port
31 }
32
33 pub fn into_inner(self) -> ServerRef {
35 self.inner
36 }
37}
38
39impl Future for TcpServerRef {
40 type Output = Result<(), JoinError>;
41
42 fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
43 Pin::new(&mut self.inner.task).poll(cx)
44 }
45}
46
47impl Deref for TcpServerRef {
48 type Target = ServerRef;
49
50 fn deref(&self) -> &Self::Target {
51 &self.inner
52 }
53}
54
55impl DerefMut for TcpServerRef {
56 fn deref_mut(&mut self) -> &mut Self::Target {
57 &mut self.inner
58 }
59}