use std::{io, string::FromUtf8Error};
use tubes::prelude::*;
pub struct Msg(pub String);
impl From<String> for Msg {
fn from(value: String) -> Self {
Self(value)
}
}
impl TryFrom<&[u8]> for Msg {
type Error = FromUtf8Error;
fn try_from(value: &[u8]) -> std::result::Result<Self, Self::Error> {
Ok(Msg(String::from_utf8(value.to_vec())?))
}
}
impl TryFrom<Msg> for Vec<u8> {
type Error = ();
fn try_from(value: Msg) -> std::result::Result<Self, Self::Error> {
Ok(value.0.into())
}
}
fn main() {
let mut s = Session::<0>::new_server(":5000".into());
s.start().unwrap();
let mut line = String::new();
loop {
io::stdin().read_line(&mut line).unwrap();
s.broadcast(line.clone().into()).unwrap();
line.clear();
}
}