use futures_lite::{AsyncWriteExt, AsyncReadExt};
use futures_lite::future::or;
use std::future::Future;
use async_net::TcpStream;
use std::fmt;
use serde::{Serialize, Deserialize};
pub use async_net;
pub mod raw;
#[cfg(feature = "async-fifo")]
pub mod async_fifo;
#[cfg(feature = "async-channel")]
pub mod async_channel;
pub trait SendFut<O>: Future<Output = O> + Send {}
impl<O, Y: Future<Output = O> + Send> SendFut<O> for Y {}
pub trait GetOutgoing<O> {
fn get_outgoing(&mut self) -> impl SendFut<Option<O>>;
}
pub trait HandleIncoming<I> {
fn handle_incoming(&mut self, incoming: I) -> impl SendFut<()>;
}
pub use traits::{Incoming, Outgoing};
#[cfg(feature = "log")]
mod traits {
use core::fmt::Debug;
use super::*;
pub trait Incoming: for<'a> Deserialize<'a> + Debug {}
impl<I: for<'a> Deserialize<'a> + Debug> Incoming for I {}
pub trait Outgoing: Serialize + Debug {}
impl<O: Serialize + Debug> Outgoing for O {}
}
#[cfg(not(feature = "log"))]
mod traits {
use super::*;
pub trait Incoming: for<'a> Deserialize<'a> {}
impl<I: for<'a> Deserialize<'a>> Incoming for I {}
pub trait Outgoing: Serialize {}
impl<O: Serialize> Outgoing for O {}
}
#[derive(Debug)]
pub enum Error {
UnexpectedEof,
Codec(serde_json::Error),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::UnexpectedEof => write!(f, "Error is here!"),
Self::Codec(serde) => serde.fmt(f),
}
}
}
impl core::error::Error for Error {}