fedimint_api_client/api/
net.rs

1use std::fmt;
2use std::str::FromStr;
3
4use fedimint_core::encoding::{Decodable, Encodable};
5use serde::{Deserialize, Serialize};
6
7#[derive(Clone, Copy, Debug, Eq, PartialEq, Encodable, Decodable, Serialize, Deserialize)]
8pub enum Connector {
9    Tcp,
10    #[cfg(feature = "tor")]
11    Tor,
12}
13
14impl Connector {
15    #[cfg(feature = "tor")]
16    pub fn tor() -> Connector {
17        Connector::Tor
18    }
19}
20
21impl Default for Connector {
22    fn default() -> Self {
23        Self::Tcp
24    }
25}
26
27impl fmt::Display for Connector {
28    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
29        write!(f, "{self:?}")
30    }
31}
32
33impl FromStr for Connector {
34    type Err = &'static str;
35
36    fn from_str(s: &str) -> Result<Self, Self::Err> {
37        match s.to_lowercase().as_str() {
38            "tcp" => Ok(Connector::Tcp),
39            #[cfg(feature = "tor")]
40            "tor" => Ok(Connector::Tor),
41            _ => Err("invalid connector!"),
42        }
43    }
44}