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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/// Exar DB's server configuration.
///
/// # Examples
/// ```
/// extern crate exar_server;
///
/// # fn main() {
/// use exar_server::*;
///
/// let config = ServerConfig {
///     host: "127.0.0.1".to_owned(),
///     port: 38580,
///     username: Some("username".to_owned()),
///     password: Some("password".to_owned())
/// };
/// # }
/// ```
#[cfg_attr(feature = "rustc-serialization", derive(RustcEncodable, RustcDecodable))]
#[cfg_attr(feature = "serde-serialization", derive(Serialize, Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ServerConfig  {
    /// The server host.
    pub host: String,
    /// The server port.
    pub port: u16,
    /// The server authentication's username.
    pub username: Option<String>,
    /// The server authentication's password.
    pub password: Option<String>
}

impl Default for ServerConfig {
    fn default() -> ServerConfig {
        ServerConfig {
            host: "127.0.0.1".to_owned(),
            port: 38580,
            username: None,
            password: None
        }
    }
}

impl ServerConfig {
    /// Returns a string representation of the server address (`host:port`).
    pub fn address(&self) -> String {
        format!("{}:{}", self.host, self.port)
    }
}