refactor: split into more logical files

This commit is contained in:
Noa Aarts 2024-10-18 01:56:23 +02:00
parent 19eb943865
commit 9dc681086d
Signed by: noa
GPG key ID: 1850932741EFF672
11 changed files with 728 additions and 276 deletions

29
src/protocols.rs Normal file
View file

@ -0,0 +1,29 @@
mod binary_protocol;
mod text_protocol;
use std::io;
pub use binary_protocol::BinaryParser;
pub use text_protocol::TextParser;
use tokio::io::AsyncWriteExt;
use crate::{Canvas, Command, Response};
pub trait Parser<R>
where
R: std::marker::Unpin + tokio::io::AsyncBufRead,
{
async fn parse(&self, reader: &mut R) -> io::Result<Command>;
}
pub trait IOProtocol {
fn change_canvas(&mut self, canvas: Canvas) -> io::Result<()>;
}
pub trait Responder<W>
where
W: AsyncWriteExt + std::marker::Unpin,
{
async fn unparse(&self, response: Response, writer: &mut W) -> io::Result<()>;
}