28 lines
876 B
Rust
28 lines
876 B
Rust
use tokio::task::JoinHandle;
|
|
use std::net::SocketAddr;
|
|
|
|
pub trait Stream {
|
|
type Socket;
|
|
|
|
fn recv(&mut self, buffer:&mut [u8]) -> Result<usize, ()>;
|
|
fn send(&mut self, buffer:&mut [u8]) -> Result<(), ()>;
|
|
fn stream(&mut self) -> &mut Self::Socket;
|
|
}
|
|
|
|
pub trait Server {
|
|
type Stream :Stream;
|
|
|
|
fn bind(&mut self, interface:&str) -> impl std::future::Future<Output = Result<(),()>>;
|
|
//async fn accept(&self) -> Result<Self::Stream, ()>;
|
|
fn accept<F, Fut, Args>(&self, callback:F, args:Args) -> impl std::future::Future<Output = Result<JoinHandle<Result<(),()>>,()>>
|
|
where
|
|
F: Fn(Self::Stream, SocketAddr, Args) -> Fut + Send + Sync + 'static,
|
|
Fut: std::future::Future<Output = Result<(),()>> + Send + 'static,
|
|
Args: Send + 'static;
|
|
fn close(&mut self);
|
|
}
|
|
|
|
pub mod tcp;
|
|
pub mod tls;
|
|
pub mod certstore;
|