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