2025-11-25 17:31:09 -07:00
|
|
|
// mod connection;
|
|
|
|
|
mod tcp_stream;
|
|
|
|
|
pub use tcp_stream::TcpStream;
|
2025-11-25 14:27:06 -07:00
|
|
|
|
2025-11-25 17:31:09 -07:00
|
|
|
// pub use connection::Connection;
|
2025-11-25 14:27:06 -07:00
|
|
|
|
|
|
|
|
use crate::ModuleError;
|
|
|
|
|
|
|
|
|
|
/// This is the data transmission type
|
|
|
|
|
pub trait Stream<T>: Send + Sync {
|
|
|
|
|
// fn get_info(&self) -> String;
|
|
|
|
|
fn is_alive(&self) -> bool;
|
|
|
|
|
|
2025-11-25 17:31:09 -07:00
|
|
|
fn has_recv(&self) -> bool;
|
|
|
|
|
|
|
|
|
|
/// Possibly blocking stream read function
|
|
|
|
|
fn read(&mut self) -> Vec<T>;
|
|
|
|
|
|
|
|
|
|
/// Non-blocking read function
|
|
|
|
|
fn try_read(&mut self) -> Vec<T> {
|
|
|
|
|
if self.has_recv() {
|
|
|
|
|
self.read()
|
|
|
|
|
} else {
|
|
|
|
|
Vec::new()
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-11-25 14:27:06 -07:00
|
|
|
|
|
|
|
|
fn write(&mut self, data: T) -> Result<(), ModuleError>;
|
|
|
|
|
|
|
|
|
|
fn try_clone(&self) -> Result<Box<dyn Stream<T> + Send + Sync>, ModuleError>;
|
|
|
|
|
}
|