From 2dae043e8ffcb030699f3523568544676e370b53 Mon Sep 17 00:00:00 2001 From: cel 🌸 Date: Fri, 29 Nov 2024 02:10:19 +0000 Subject: add some tracing --- src/element.rs | 17 +++++++++++++++-- src/error.rs | 1 + src/reader.rs | 5 ++++- src/writer.rs | 1 + 4 files changed, 21 insertions(+), 3 deletions(-) (limited to 'src') 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) = ::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), UnexpectedContent(VecDeque), + 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 { inner: R, pub buffer: Buffer, @@ -59,7 +61,7 @@ impl Reader where R: AsyncRead + Unpin, { - async fn read_buf<'s>(&mut self) -> Result { + pub async fn read_buf<'s>(&mut self) -> Result { 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 { 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 { +#[derive(Debug)] pub struct Writer { inner: W, depth: Vec, -- cgit