aboutsummaryrefslogtreecommitdiffstats
path: root/src/reader.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/reader.rs')
-rw-r--r--src/reader.rs46
1 files changed, 39 insertions, 7 deletions
diff --git a/src/reader.rs b/src/reader.rs
index 6e622f4..2785c88 100644
--- a/src/reader.rs
+++ b/src/reader.rs
@@ -1,5 +1,7 @@
use futures::Stream;
-use tokio::io::AsyncBufRead;
+use nom::Err;
+use std::str;
+use tokio::io::AsyncBufReadExt;
use crate::{
element::{Element, Name, Namespace},
@@ -8,20 +10,50 @@ use crate::{
/// streaming reader that tracks depth and available namespaces at current depth
pub struct Reader<R> {
- stream: R,
+ inner: R,
// holds which tags we are in atm over depth
depth: Vec<Name>,
namespaces: Vec<(usize, Namespace)>,
}
+impl<R> Reader<R> {
+ pub fn new(reader: R) -> Self {
+ Self {
+ inner: reader,
+ depth: Vec::new(),
+ namespaces: Vec::new(),
+ }
+ }
+}
+
impl<R> Reader<R>
where
- R: AsyncBufRead,
+ R: AsyncBufReadExt + Unpin,
{
- // pub async fn read(&self) -> Result<impl From<Element>, Error> {
- // let buf = self.stream.poll_fill_buf().await?;
- // todo!()
- // }
+ /// reads entire next prolog, element, or misc
+ pub async fn read<'s>(&'s mut self) -> Result<crate::xml::Element<'s>, Error> {
+ let element;
+ let len;
+ loop {
+ let buf = self.inner.fill_buf().await?;
+ let input = str::from_utf8(buf)?;
+ match crate::xml::element(input) {
+ Ok((rest, e)) => {
+ element = e;
+ len = buf.len() - rest.len();
+ break;
+ }
+ Err(e) => match e {
+ Err::Incomplete(_) => (),
+ e => return Err(Error::ParseError(input.to_owned())),
+ },
+ }
+ }
+ self.inner.consume(len);
+
+ // Ok(element)
+ todo!()
+ }
// pub async fn read_start(&self) -> Result<impl From<Element>, Error> {
// todo!()
// }