Start rewrite, get layers working

This commit is contained in:
Michael Mikovsky
2025-06-09 12:37:49 -06:00
parent 6ac1b5214e
commit a148e4e0a8
31 changed files with 527 additions and 792 deletions
+50
View File
@@ -0,0 +1,50 @@
use std::net::SocketAddr;
use std::ops::Deref;
use std::ops::DerefMut;
use crate::Error;
// This is the lowset-level data transmission type
pub trait Connection: Send {
fn get_info(&self) -> String;
fn is_alive(&self) -> bool;
fn read(&mut self) -> Result<String, Error>;
fn write(&mut self, data: &str) -> Result<(), Error>;
}
// Trait for protocol layers that can be initialized
pub trait ProtocolLayer<C: Connection>: Connection {
fn new(inner: C) -> Result<Self, Error>
where
Self: Sized;
fn initialize_client(&mut self) -> Result<(), Error> {
Ok(())
}
fn initialize_server(&mut self) -> Result<(), Error> {
Ok(())
}
}
// impl Sized for dyn Connection {}
// pub trait AsyncConnection<C>
// where
// C: Connection,
// {
// fn as_async<T: Serialize + DeserializeOwned + Send + 'static>(
// connection: C,
// ) -> (Sender<T>, Receiver<T>);
// }
pub trait ServerTrait<C: Connection> {
fn get_info(&self) -> String;
fn accept(&self) -> Result<C, Error>;
fn bind(address: &SocketAddr) -> Result<Self, Error>
where
Self: Sized;
}
pub trait ClientTrait<C: Connection + Sized> {
fn connect(address: &SocketAddr) -> Result<C, Error>;
}