mirror of
https://github.com/lennart-k/rustical.git
synced 2026-01-30 14:08:23 +00:00
Migrate propfind and report to rustical_xml
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
use quick_xml::events::{BytesStart, Event};
|
||||
use std::num::{ParseFloatError, ParseIntError};
|
||||
use std::str::FromStr;
|
||||
use std::{convert::Infallible, io::BufRead};
|
||||
use thiserror::Error;
|
||||
|
||||
@@ -21,6 +20,21 @@ pub trait Value: Sized {
|
||||
fn deserialize(val: &str) -> Result<Self, XmlDeError>;
|
||||
}
|
||||
|
||||
// impl<T: Value> Value for Option<T> {
|
||||
// fn serialize(&self) -> String {
|
||||
// match self {
|
||||
// Some(inner) => inner.serialize(),
|
||||
// None => "".to_owned(),
|
||||
// }
|
||||
// }
|
||||
// fn deserialize(val: &str) -> Result<Self, XmlDeError> {
|
||||
// match val {
|
||||
// "" => Ok(None),
|
||||
// val => Ok(Some(T::deserialize(val)?)),
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
macro_rules! impl_value_parse {
|
||||
($t:ty) => {
|
||||
impl Value for $t {
|
||||
@@ -54,7 +68,7 @@ impl_value_parse!(usize);
|
||||
impl<T: Value> XmlDeserialize for T {
|
||||
fn deserialize<R: BufRead>(
|
||||
reader: &mut quick_xml::NsReader<R>,
|
||||
start: &BytesStart,
|
||||
_start: &BytesStart,
|
||||
empty: bool,
|
||||
) -> Result<Self, XmlDeError> {
|
||||
let mut string = String::new();
|
||||
@@ -64,17 +78,19 @@ impl<T: Value> XmlDeserialize for T {
|
||||
loop {
|
||||
match reader.read_event_into(&mut buf)? {
|
||||
Event::Text(text) => {
|
||||
if !start.is_empty() {
|
||||
if !string.is_empty() {
|
||||
// Content already written
|
||||
return Err(XmlDeError::UnsupportedEvent("todo"));
|
||||
return Err(XmlDeError::UnsupportedEvent("content already written"));
|
||||
}
|
||||
string = String::from_utf8_lossy(text.as_ref()).to_string();
|
||||
}
|
||||
Event::End(_) => break,
|
||||
Event::Eof => return Err(XmlDeError::Eof),
|
||||
_ => return Err(XmlDeError::UnsupportedEvent("todo")),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
<Self as Value>::deserialize(&string)
|
||||
Value::deserialize(&string)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user