From aa940a8eac74aca8cd3c202a05092538d1140dda Mon Sep 17 00:00:00 2001 From: cel 🌸 Date: Thu, 28 Nov 2024 18:00:30 +0000 Subject: create element builder and refactor api --- src/reader.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/reader.rs') diff --git a/src/reader.rs b/src/reader.rs index e6bb57c..aa4d467 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -2,7 +2,7 @@ use circular::Buffer; use futures::{FutureExt, Stream}; use nom::Err; use std::{ - collections::{hash_set, BTreeMap, HashMap, HashSet}, + collections::{hash_set, BTreeMap, HashMap, HashSet, VecDeque}, future::Future, path::Prefix, pin::{pin, Pin}, @@ -102,12 +102,12 @@ where pub async fn read_start<'s, T: FromElement>(&'s mut self) -> Result { let element = self.read_start_tag().await?; - FromElement::from_element(element) + Ok(FromElement::from_element(element)?) } pub async fn read<'s, T: FromElement>(&'s mut self) -> Result { let element = self.read_element().await?; - FromElement::from_element(element) + Ok(FromElement::from_element(element)?) } pub async fn read_start_tag<'s>(&'s mut self) -> Result { @@ -438,7 +438,7 @@ impl Reader { name: element_name, namespace_declaration_overrides: element_namespace_declarations, attributes, - content: Vec::new(), + content: VecDeque::new(), }); } @@ -652,7 +652,7 @@ impl Reader { namespace_declarations.pop(); } else { - content = Vec::new(); + content = VecDeque::new(); } return Ok(Element { @@ -666,18 +666,18 @@ impl Reader { fn content_from_xml( namespaces: &mut Vec>, xml_content: xml::Content, - ) -> Result> { - let mut content = Vec::new(); + ) -> Result> { + let mut content = VecDeque::new(); let mut text = xml_content.char_data.map(|str| String::from(*str)); for (content_item, char_data) in xml_content.content { match content_item { xml::ContentItem::Element(element) => { text.map(|text| { if !text.is_empty() { - content.push(Content::Text(text)) + content.push_back(Content::Text(text)) } }); - content.push(Content::Element(Self::element_from_xml( + content.push_back(Content::Element(Self::element_from_xml( namespaces, element, )?)); text = char_data.map(|str| String::from(*str)); @@ -711,7 +711,7 @@ impl Reader { } text.map(|text| { if !text.is_empty() { - content.push(Content::Text(text)) + content.push_back(Content::Text(text)) } }); Ok(content) -- cgit