diff options
author | 2024-11-29 02:10:19 +0000 | |
---|---|---|
committer | 2024-11-29 02:10:19 +0000 | |
commit | 2dae043e8ffcb030699f3523568544676e370b53 (patch) | |
tree | 52669190c01bd5d7da03d1c9181d00eb23a21124 /src | |
parent | aa940a8eac74aca8cd3c202a05092538d1140dda (diff) | |
download | peanuts-2dae043e8ffcb030699f3523568544676e370b53.tar.gz peanuts-2dae043e8ffcb030699f3523568544676e370b53.tar.bz2 peanuts-2dae043e8ffcb030699f3523568544676e370b53.zip |
add some tracing
Diffstat (limited to 'src')
-rw-r--r-- | src/element.rs | 17 | ||||
-rw-r--r-- | src/error.rs | 1 | ||||
-rw-r--r-- | src/reader.rs | 5 | ||||
-rw-r--r-- | src/writer.rs | 1 |
4 files changed, 21 insertions, 3 deletions
diff --git a/src/element.rs b/src/element.rs index 98a3315..1f78419 100644 --- a/src/element.rs +++ b/src/element.rs @@ -8,6 +8,8 @@ use std::{ str::FromStr, }; +use tracing::debug; + use crate::{ error::{DeserializeError, Error}, xml::{self, parsers_complete::Parser, Attribute}, @@ -322,17 +324,28 @@ impl Element { let mut children = Vec::new(); loop { let child = self.content.front(); + debug!("child: {:?}", child); if let Some(child) = child { match child { Content::Element(element) => { if let Ok(child) = <T as FromElement>::from_element(element.clone()) { + debug!("parsed child"); children.push(child); self.content.pop_front(); + } else { + debug!("failed to parse child"); + return Ok(children); } } Content::Text(_) => return Ok(children), - Content::PI => {} - Content::Comment(_) => {} + Content::PI => { + self.content.pop_front(); + continue; + } + Content::Comment(_) => { + self.content.pop_front(); + continue; + } } } else { return Ok(children); diff --git a/src/error.rs b/src/error.rs index dd8ea17..0cac59b 100644 --- a/src/error.rs +++ b/src/error.rs @@ -14,6 +14,7 @@ pub enum DeserializeError { FromStr(String), UnexpectedAttributes(HashMap<Name, String>), UnexpectedContent(VecDeque<Content>), + UnexpectedElement(Element), MissingAttribute(Name), IncorrectName(String), IncorrectNamespace(String), diff --git a/src/reader.rs b/src/reader.rs index aa4d467..d2de170 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -9,6 +9,7 @@ use std::{ str::{self, FromStr}, }; use tokio::io::{AsyncBufRead, AsyncBufReadExt, AsyncRead, AsyncReadExt}; +use tracing::debug; use crate::{ declaration::{Declaration, VersionInfo}, @@ -21,6 +22,7 @@ use crate::{ static MAX_STANZA_SIZE: usize = 65536; /// streaming reader that tracks depth and available namespaces at current depth +#[derive(Debug)] pub struct Reader<R> { inner: R, pub buffer: Buffer, @@ -59,7 +61,7 @@ impl<R> Reader<R> where R: AsyncRead + Unpin, { - async fn read_buf<'s>(&mut self) -> Result<usize> { + pub async fn read_buf<'s>(&mut self) -> Result<usize> { Ok(self.inner.read_buf(&mut self.buffer).await?) } @@ -107,6 +109,7 @@ where pub async fn read<'s, T: FromElement>(&'s mut self) -> Result<T> { let element = self.read_element().await?; + debug!("read element: {:?}", element); Ok(FromElement::from_element(element)?) } diff --git a/src/writer.rs b/src/writer.rs index 8b45869..25e19fb 100644 --- a/src/writer.rs +++ b/src/writer.rs @@ -13,6 +13,7 @@ use crate::{ }; // pub struct Writer<W, C = Composer> { +#[derive(Debug)] pub struct Writer<W> { inner: W, depth: Vec<Name>, |