add some tracing

This commit is contained in:
cel 🌸 2024-11-29 02:10:19 +00:00
parent aa940a8eac
commit 2dae043e8f
6 changed files with 60 additions and 3 deletions

38
Cargo.lock generated
View File

@ -256,6 +256,12 @@ version = "0.24.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a5b3dd1c072ee7963717671d1ca129f1048fda25edea6b752bfc71ac8854170" checksum = "1a5b3dd1c072ee7963717671d1ca129f1048fda25edea6b752bfc71ac8854170"
[[package]]
name = "once_cell"
version = "1.20.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775"
[[package]] [[package]]
name = "parking_lot" name = "parking_lot"
version = "0.12.3" version = "0.12.3"
@ -288,6 +294,7 @@ dependencies = [
"futures", "futures",
"nom", "nom",
"tokio", "tokio",
"tracing",
] ]
[[package]] [[package]]
@ -416,6 +423,37 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "tracing"
version = "0.1.41"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0"
dependencies = [
"pin-project-lite",
"tracing-attributes",
"tracing-core",
]
[[package]]
name = "tracing-attributes"
version = "0.1.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "395ae124c09f9e6918a2310af6038fba074bcf474ac352496d5910dd59a2226d"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "tracing-core"
version = "0.1.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e672c95779cf947c5311f83787af4fa8fffd12fb27e4993211a84bdfd9610f9c"
dependencies = [
"once_cell",
]
[[package]] [[package]]
name = "unicode-ident" name = "unicode-ident"
version = "1.0.12" version = "1.0.12"

View File

@ -11,3 +11,4 @@ circular = { version = "0.3.0", path = "../circular" }
futures = "0.3.30" futures = "0.3.30"
nom = "7.1.3" nom = "7.1.3"
tokio = { version = "1.36.0", features = ["io-util", "net", "io-std", "full"] } tokio = { version = "1.36.0", features = ["io-util", "net", "io-std", "full"] }
tracing = "0.1.41"

View File

@ -8,6 +8,8 @@ use std::{
str::FromStr, str::FromStr,
}; };
use tracing::debug;
use crate::{ use crate::{
error::{DeserializeError, Error}, error::{DeserializeError, Error},
xml::{self, parsers_complete::Parser, Attribute}, xml::{self, parsers_complete::Parser, Attribute},
@ -322,17 +324,28 @@ impl Element {
let mut children = Vec::new(); let mut children = Vec::new();
loop { loop {
let child = self.content.front(); let child = self.content.front();
debug!("child: {:?}", child);
if let Some(child) = child { if let Some(child) = child {
match child { match child {
Content::Element(element) => { Content::Element(element) => {
if let Ok(child) = <T as FromElement>::from_element(element.clone()) { if let Ok(child) = <T as FromElement>::from_element(element.clone()) {
debug!("parsed child");
children.push(child); children.push(child);
self.content.pop_front(); self.content.pop_front();
} else {
debug!("failed to parse child");
return Ok(children);
} }
} }
Content::Text(_) => return Ok(children), Content::Text(_) => return Ok(children),
Content::PI => {} Content::PI => {
Content::Comment(_) => {} self.content.pop_front();
continue;
}
Content::Comment(_) => {
self.content.pop_front();
continue;
}
} }
} else { } else {
return Ok(children); return Ok(children);

View File

@ -14,6 +14,7 @@ pub enum DeserializeError {
FromStr(String), FromStr(String),
UnexpectedAttributes(HashMap<Name, String>), UnexpectedAttributes(HashMap<Name, String>),
UnexpectedContent(VecDeque<Content>), UnexpectedContent(VecDeque<Content>),
UnexpectedElement(Element),
MissingAttribute(Name), MissingAttribute(Name),
IncorrectName(String), IncorrectName(String),
IncorrectNamespace(String), IncorrectNamespace(String),

View File

@ -9,6 +9,7 @@ use std::{
str::{self, FromStr}, str::{self, FromStr},
}; };
use tokio::io::{AsyncBufRead, AsyncBufReadExt, AsyncRead, AsyncReadExt}; use tokio::io::{AsyncBufRead, AsyncBufReadExt, AsyncRead, AsyncReadExt};
use tracing::debug;
use crate::{ use crate::{
declaration::{Declaration, VersionInfo}, declaration::{Declaration, VersionInfo},
@ -21,6 +22,7 @@ use crate::{
static MAX_STANZA_SIZE: usize = 65536; static MAX_STANZA_SIZE: usize = 65536;
/// streaming reader that tracks depth and available namespaces at current depth /// streaming reader that tracks depth and available namespaces at current depth
#[derive(Debug)]
pub struct Reader<R> { pub struct Reader<R> {
inner: R, inner: R,
pub buffer: Buffer, pub buffer: Buffer,
@ -59,7 +61,7 @@ impl<R> Reader<R>
where where
R: AsyncRead + Unpin, 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?) 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> { pub async fn read<'s, T: FromElement>(&'s mut self) -> Result<T> {
let element = self.read_element().await?; let element = self.read_element().await?;
debug!("read element: {:?}", element);
Ok(FromElement::from_element(element)?) Ok(FromElement::from_element(element)?)
} }

View File

@ -13,6 +13,7 @@ use crate::{
}; };
// pub struct Writer<W, C = Composer> { // pub struct Writer<W, C = Composer> {
#[derive(Debug)]
pub struct Writer<W> { pub struct Writer<W> {
inner: W, inner: W,
depth: Vec<Name>, depth: Vec<Name>,