delta/network/
connection_params.rs

1/// Represents the connection parameters for a Delta node.
2///
3/// `ConnectionParams` can be:
4/// - `Url`: A URL string to connect to a node.
5/// - `IpPort`: An IP address and port combination to connect to a node.
6#[derive(Clone, Debug)]
7pub enum ConnectionParams {
8    /// Connection parameter representing a URL.
9    ///
10    /// # Fields
11    /// * `0` - A string containing the URL.
12    Url(String),
13    /// Connection parameter representing an IP address and port.
14    ///
15    /// # Fields
16    /// * `0` - A string containing the IP address.
17    /// * `1` - A u16 containing the port number.
18    IpPort(String, u16),
19}
20
21impl ConnectionParams {
22    /// Checks if the connection parameters are a URL.
23    ///
24    /// # Returns
25    ///
26    /// A boolean indicating whether the connection parameters are a URL.
27    ///
28    /// # Examples
29    ///
30    /// ```
31    /// let params = ConnectionParams::Url("http://example.com".to_string());
32    /// assert!(params.is_url());
33    /// assert!(!params.is_ip_port());
34    /// ```
35    pub fn is_url(&self) -> bool {
36        matches!(self, ConnectionParams::Url(_))
37    }
38
39    /// Checks if the connection parameters are an IP address and port combination.
40    ///
41    /// # Returns
42    ///
43    /// A boolean indicating whether the connection parameters are an IP address and port combination.
44    ///
45    /// # Examples
46    ///
47    /// ```
48    /// let params = ConnectionParams::IpPort("192.168.1.1".to_string(), 8080);
49    /// assert!(params.is_ip_port());
50    /// assert!(!params.is_url());
51    /// ```
52    pub fn is_ip_port(&self) -> bool {
53        matches!(self, ConnectionParams::IpPort(_, _))
54    }
55}