Files
lan-mouse/src/config.rs
Ferdinand Schober 5222f54eee major refactor
every instance of lan-mouse can now simultaneously send and receive
events
2023-01-30 19:15:58 +01:00

33 lines
753 B
Rust

use serde_derive::{Deserialize, Serialize};
use std::net::IpAddr;
use std::{error::Error, fs};
use toml;
#[derive(Serialize, Deserialize, Debug)]
pub struct Config {
pub client: Clients,
pub port: Option<u16>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Clients {
pub left: Option<Client>,
pub right: Option<Client>,
pub top: Option<Client>,
pub bottom: Option<Client>,
}
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
pub struct Client {
pub host_name: Option<String>,
pub ip: Option<IpAddr>,
pub port: Option<u16>,
}
impl Config {
pub fn new(path: &str) -> Result<Config, Box<dyn Error>> {
let config = fs::read_to_string(path)?;
Ok(toml::from_str::<_>(&config)?)
}
}