use futures::Stream; use nom::Err; use std::{collections::BTreeMap, str}; use tokio::io::AsyncBufReadExt; use crate::{ element::{Element, Name, Namespace}, error::Error, }; /// streaming reader that tracks depth and available namespaces at current depth pub struct Reader { inner: R, // holds which tags we are in atm over depth depth: Vec, namespaces: Vec<(usize, Namespace)>, } impl Reader { pub fn new(reader: R) -> Self { Self { inner: reader, depth: Vec::new(), namespaces: Vec::new(), } } } impl Reader where R: AsyncBufReadExt + Unpin, { /// could resursively read and include namespace tree with values to be shadowed within new local context async fn read_recursive(&mut self, namespaces: BTreeMap, String>) -> Result { 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())), }, } } let final; match element { crate::xml::Element::Empty(e) => { let final = Element { } }, crate::xml::Element::NotEmpty(_, _, _) => todo!(), } self.inner.consume(len); todo!() } /// reads entire next prolog, element, or misc // pub async fn read>(&mut self) -> Result { // 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, Error> { // todo!() // } // pub async fn read_end(&self) -> Result<(), Error> { // todo!() // } } // impl Stream for Reader { // type Item = impl From; // async fn poll_next( // self: std::pin::Pin<&mut Self>, // cx: &mut std::task::Context<'_>, // ) -> std::task::Poll> { // todo!() // } // }