use tokio::io::{AsyncBufRead, AsyncBufReadExt, BufReader, Lines};
use crate::Result;
use super::CrocEvent;
pub struct CrocParser<R: AsyncBufRead + Unpin> {
lines: Lines<BufReader<R>>,
}
impl<R: AsyncBufRead + Unpin> CrocParser<R> {
pub fn new(inner: R) -> Self {
let reader = BufReader::new(inner);
let lines = reader.lines();
Self { lines }
}
pub async fn parse_next_event(&mut self) -> Result<CrocEvent> {
if let Some(line) = self.lines.next_line().await? {
Ok(CrocEvent::Unknown(line))
} else {
Ok(CrocEvent::EOF)
}
}
}