summaryrefslogtreecommitdiffstats
path: root/src/service/tcp.rs
blob: 87e696a4c6afb6535f517cf66eb1107075fb79d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
use std::fmt::Display;

use serde::Deserialize;

use crate::{Error, Status};

#[derive(Debug, Clone, Deserialize)]
pub struct Tcp {
    pub address: String,
}

impl Display for Tcp {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "tcp://{}", self.address)
    }
}

impl Tcp {
    pub async fn check(&self) -> Result<Status, Error> {
        Ok(std::net::TcpStream::connect(&self.address)
            .err()
            .map(Into::into)
            .unwrap_or_default())
    }
}