aboutsummaryrefslogtreecommitdiffstats
path: root/mumlib/src/config.rs
diff options
context:
space:
mode:
authorEskil Queseth <eskilq@kth.se>2020-10-31 02:27:26 +0100
committerEskil Queseth <eskilq@kth.se>2020-10-31 02:27:26 +0100
commit11c823701b12f10933b40044a12cc4048ccf8bd2 (patch)
treeb3d0b6c844383f8a45cd5081459928b75136ab95 /mumlib/src/config.rs
parent8fb4edd72dfcb2b71e91eedc5861360101374967 (diff)
downloadmum-11c823701b12f10933b40044a12cc4048ccf8bd2.tar.gz
add support for mumctl server list
Diffstat (limited to 'mumlib/src/config.rs')
-rw-r--r--mumlib/src/config.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/mumlib/src/config.rs b/mumlib/src/config.rs
index e6b97fd..e7d107a 100644
--- a/mumlib/src/config.rs
+++ b/mumlib/src/config.rs
@@ -4,6 +4,8 @@ use std::fs;
use std::path::Path;
use toml::value::Array;
use toml::Value;
+use std::net::{SocketAddr, ToSocketAddrs};
+use crate::DEFAULT_PORT;
#[derive(Debug, Deserialize, Serialize)]
struct TOMLConfig {
@@ -58,6 +60,15 @@ 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);