use std::ops::DerefMut;
use std::pin::Pin;
#[derive(Debug)]
#[non_exhaustive]
pub struct Context {
is_first_line: bool,
}
impl Default for Context {
fn default() -> Self {
Self {
is_first_line: true,
}
}
}
impl Context {
#[inline]
#[must_use]
pub fn is_first_line(&self) -> bool {
self.is_first_line
}
#[inline]
pub fn set_is_first_line(&mut self, is_first_line: bool) {
self.is_first_line = is_first_line;
}
}
pub type Error = std::io::Error;
pub type Result = std::result::Result<String, Error>;
#[must_use = "Input instances should be used by a parser"]
pub trait Input {
fn next_line(&mut self, context: &Context) -> impl Future<Output = Result>;
}
impl<T> Input for T
where
T: DerefMut,
T::Target: Input,
{
fn next_line(&mut self, context: &Context) -> impl Future<Output = Result> {
self.deref_mut().next_line(context)
}
}
pub trait InputObject {
fn next_line<'a>(
&'a mut self,
context: &'a Context,
) -> Pin<Box<dyn Future<Output = Result> + 'a>>;
}
impl<T: Input> InputObject for T {
fn next_line<'a>(
&'a mut self,
context: &'a Context,
) -> Pin<Box<dyn Future<Output = Result> + 'a>> {
Box::pin(Input::next_line(self, context))
}
}
mod memory;
pub use memory::Memory;
mod fd_reader;
pub use fd_reader::FdReader;
mod fd_reader_2;
pub use fd_reader_2::FdReader2;
mod echo;
pub use echo::Echo;
mod ignore_eof;
pub use ignore_eof::IgnoreEof;
mod reporter;
pub use reporter::Reporter;