aboutsummaryrefslogtreecommitdiffstats
path: root/mumlib/src/config.rs
diff options
context:
space:
mode:
Diffstat (limited to 'mumlib/src/config.rs')
-rw-r--r--mumlib/src/config.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/mumlib/src/config.rs b/mumlib/src/config.rs
index 2eca104..3a2fa27 100644
--- a/mumlib/src/config.rs
+++ b/mumlib/src/config.rs
@@ -1,6 +1,8 @@
+use crate::DEFAULT_PORT;
use serde::{Deserialize, Serialize};
use std::convert::TryFrom;
use std::fs;
+use std::net::{SocketAddr, ToSocketAddrs};
use std::path::Path;
use toml::value::Array;
use toml::Value;
@@ -59,6 +61,18 @@ pub struct ServerConfig {
pub password: Option<String>,
}
+impl ServerConfig {
+ pub fn to_socket_addr(&self) -> Option<SocketAddr> {
+ match (self.host.as_str(), self.port.unwrap_or(DEFAULT_PORT))
+ .to_socket_addrs()
+ .map(|mut e| e.next())
+ {
+ Ok(Some(addr)) => Some(addr),
+ _ => None,
+ }
+ }
+}
+
pub fn get_cfg_path() -> String {
if let Ok(var) = std::env::var("XDG_CONFIG_HOME") {
let path = format!("{}/mumdrc", var);