nutt-conf-parser 0.2.0

Parser for nutt-web config file
Documentation
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct NuttConfig {
    project: ProjectConfig,
    service: HashMap<String, ServiceConfig>,
}

impl NuttConfig {
    pub fn new(name: &str, version: &str) -> Self {
        Self {
            project: ProjectConfig::new(name, version),
            service: HashMap::new(),
        }
    }

    pub fn get_service_config(&self, name: &str) -> Option<ServiceConfig> {
        if let Some(conf) = self.service.get(name) {
            return Some(conf.clone());
        }
        None
    }

    pub fn push_service_config(&mut self,name: &str, service_config: ServiceConfig) {
        self.service.insert(name.to_string(), service_config);
    }
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct ServiceConfig {
    local_host: String,
    local_port: u16,
}

impl ServiceConfig {
    pub fn new(local_host: &str, local_port: u16) -> Self {
        Self {
            local_host: local_host.to_string(),
            local_port,
        }
    }

    pub fn get_addr(&self) -> (&str, u16) {
        (&self.local_host, self.local_port)
    }
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct ProjectConfig {
    name: String,
    version: String
}

impl ProjectConfig {
    pub fn new(name: &str, version: &str) -> Self {
        Self {
            name: name.to_string(),
            version: version.to_string()
        }
    }
}