freechat/tui/src/types.rs
2021-01-18 16:39:21 -08:00

37 lines
884 B
Rust

use serde::{Serialize,Deserialize};
use std::net::Ipv4Addr;
use std::str::FromStr;
#[derive(Debug, Deserialize, Serialize)]
pub struct Server {
pub name: Option<String>,
pub domain: Option<String>,
pub ip: String,
pub port: u16,
pub description: Option<String>,
pub key: String, // the secret hush hush uwu
pub id: u64,
pub nickname: Option<String>
}
#[derive(Deserialize, Serialize)]
pub struct Config {
pub username: String, // global username that is only overriden in server context's if nickname is used
pub servers: Vec<Server>
}
#[derive(Debug, Deserialize)]
pub struct Channel {
pub ip: String,
pub name: String,
}
impl Channel {
pub fn parts(&self) -> (Ipv4Addr, &str) {
// return the ip/name of the channel
let addr = Ipv4Addr::from_str(&self.ip).unwrap();
(addr, self.name.as_ref())
}
}