mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 21:42:34 +00:00
xml: Rename XmlDeError to XmlError
This commit is contained in:
@@ -23,12 +23,12 @@ pub(crate) enum SyncLevel {
|
||||
}
|
||||
|
||||
impl ValueDeserialize for SyncLevel {
|
||||
fn deserialize(val: &str) -> Result<Self, rustical_xml::XmlDeError> {
|
||||
fn deserialize(val: &str) -> Result<Self, rustical_xml::XmlError> {
|
||||
Ok(match val {
|
||||
"1" => Self::One,
|
||||
"Infinity" => Self::Infinity,
|
||||
_ => {
|
||||
return Err(rustical_xml::XmlDeError::Other(
|
||||
return Err(rustical_xml::XmlError::Other(
|
||||
"Invalid sync-level".to_owned(),
|
||||
))
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ pub enum Error {
|
||||
DavError(#[from] rustical_dav::Error),
|
||||
|
||||
#[error(transparent)]
|
||||
XmlDecodeError(#[from] rustical_xml::XmlDeError),
|
||||
XmlDecodeError(#[from] rustical_xml::XmlError),
|
||||
|
||||
#[error(transparent)]
|
||||
Other(#[from] anyhow::Error),
|
||||
|
||||
@@ -22,12 +22,12 @@ pub(crate) enum SyncLevel {
|
||||
}
|
||||
|
||||
impl ValueDeserialize for SyncLevel {
|
||||
fn deserialize(val: &str) -> Result<Self, rustical_xml::XmlDeError> {
|
||||
fn deserialize(val: &str) -> Result<Self, rustical_xml::XmlError> {
|
||||
Ok(match val {
|
||||
"1" => Self::One,
|
||||
"Infinity" => Self::Infinity,
|
||||
_ => {
|
||||
return Err(rustical_xml::XmlDeError::Other(
|
||||
return Err(rustical_xml::XmlError::Other(
|
||||
"Invalid sync-level".to_owned(),
|
||||
))
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ pub enum Error {
|
||||
DavError(#[from] rustical_dav::Error),
|
||||
|
||||
#[error(transparent)]
|
||||
XmlDecodeError(#[from] rustical_xml::XmlDeError),
|
||||
XmlDecodeError(#[from] rustical_xml::XmlError),
|
||||
|
||||
#[error(transparent)]
|
||||
Other(#[from] anyhow::Error),
|
||||
|
||||
@@ -20,7 +20,7 @@ pub enum Error {
|
||||
PropReadOnly,
|
||||
|
||||
#[error(transparent)]
|
||||
XmlDeserializationError(#[from] rustical_xml::XmlDeError),
|
||||
XmlDeserializationError(#[from] rustical_xml::XmlError),
|
||||
|
||||
#[error(transparent)]
|
||||
IOError(#[from] std::io::Error),
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use crate::xml::multistatus::PropstatElement;
|
||||
use actix_web::http::StatusCode;
|
||||
use reqwest::Url;
|
||||
use rustical_store::{CollectionOperation, CollectionOperationType, SubscriptionStore};
|
||||
use rustical_xml::{XmlRootTag, XmlSerialize, XmlSerializeRoot};
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -22,12 +22,12 @@ pub const LOCAL_DATE: &str = "%Y%m%d";
|
||||
pub struct UtcDateTime(DateTime<Utc>);
|
||||
|
||||
impl ValueDeserialize for UtcDateTime {
|
||||
fn deserialize(val: &str) -> Result<Self, rustical_xml::XmlDeError> {
|
||||
fn deserialize(val: &str) -> Result<Self, rustical_xml::XmlError> {
|
||||
let input = <String as ValueDeserialize>::deserialize(val)?;
|
||||
Ok(Self(
|
||||
NaiveDateTime::parse_from_str(&input, UTC_DATE_TIME)
|
||||
.map_err(|_| {
|
||||
rustical_xml::XmlDeError::Other("Could not parse as UTC timestamp".to_owned())
|
||||
rustical_xml::XmlError::Other("Could not parse as UTC timestamp".to_owned())
|
||||
})?
|
||||
.and_utc(),
|
||||
))
|
||||
|
||||
@@ -158,7 +158,7 @@ impl Field {
|
||||
(false, false, true) => quote! { builder.#builder_field_ident },
|
||||
(false, false, false) => {
|
||||
let field_ident = self.field_ident().into_token_stream().to_string();
|
||||
quote! { builder.#builder_field_ident.ok_or(::rustical_xml::XmlDeError::MissingField(#field_ident))? }
|
||||
quote! { builder.#builder_field_ident.ok_or(::rustical_xml::XmlError::MissingField(#field_ident))? }
|
||||
}
|
||||
};
|
||||
quote! { #target_field_index: #builder_value }
|
||||
|
||||
@@ -28,10 +28,10 @@ impl Enum {
|
||||
reader: &mut quick_xml::NsReader<R>,
|
||||
start: &quick_xml::events::BytesStart,
|
||||
empty: bool
|
||||
) -> Result<Self, rustical_xml::XmlDeError> {
|
||||
) -> Result<Self, rustical_xml::XmlError> {
|
||||
#(#variant_branches);*
|
||||
|
||||
Err(rustical_xml::XmlDeError::InvalidVariant("could not match".to_owned()))
|
||||
Err(rustical_xml::XmlError::InvalidVariant("could not match".to_owned()))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -49,14 +49,14 @@ impl Enum {
|
||||
reader: &mut quick_xml::NsReader<R>,
|
||||
start: &quick_xml::events::BytesStart,
|
||||
empty: bool
|
||||
) -> Result<Self, rustical_xml::XmlDeError> {
|
||||
) -> Result<Self, rustical_xml::XmlError> {
|
||||
let (_ns, name) = reader.resolve_element(start.name());
|
||||
|
||||
match name.as_ref() {
|
||||
#(#variant_branches),*
|
||||
name => {
|
||||
// Handle invalid variant name
|
||||
Err(rustical_xml::XmlDeError::InvalidVariant(String::from_utf8_lossy(name).to_string()))
|
||||
Err(rustical_xml::XmlError::InvalidVariant(String::from_utf8_lossy(name).to_string()))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -150,7 +150,7 @@ impl Enum {
|
||||
|
||||
quote! {
|
||||
impl #impl_generics ::rustical_xml::XmlDocument for #ident #type_generics #where_clause {
|
||||
fn parse<R: ::std::io::BufRead>(mut reader: ::quick_xml::NsReader<R>) -> Result<Self, ::rustical_xml::XmlDeError>
|
||||
fn parse<R: ::std::io::BufRead>(mut reader: ::quick_xml::NsReader<R>) -> Result<Self, ::rustical_xml::XmlError>
|
||||
where
|
||||
Self: ::rustical_xml::XmlDeserialize
|
||||
{
|
||||
@@ -166,26 +166,26 @@ impl Enum {
|
||||
return <Self as ::rustical_xml::XmlDeserialize>::deserialize(&mut reader, &start, empty);
|
||||
}
|
||||
|
||||
Event::Eof => return Err(::rustical_xml::XmlDeError::Eof),
|
||||
Event::Eof => return Err(::rustical_xml::XmlError::Eof),
|
||||
Event::Text(bytes_text) => {
|
||||
return Err(::rustical_xml::XmlDeError::UnsupportedEvent("Text"));
|
||||
return Err(::rustical_xml::XmlError::UnsupportedEvent("Text"));
|
||||
}
|
||||
Event::CData(cdata) => {
|
||||
return Err(::rustical_xml::XmlDeError::UnsupportedEvent("CDATA"));
|
||||
return Err(::rustical_xml::XmlError::UnsupportedEvent("CDATA"));
|
||||
}
|
||||
Event::Comment(_) => { /* ignore */ }
|
||||
Event::Decl(_) => {
|
||||
/* ignore */
|
||||
// return Err(::rustical_xml::XmlDeError::UnsupportedEvent("Declaration"));
|
||||
// return Err(::rustical_xml::XmlError::UnsupportedEvent("Declaration"));
|
||||
}
|
||||
Event::PI(_) => {
|
||||
return Err(::rustical_xml::XmlDeError::UnsupportedEvent("Processing instruction"));
|
||||
return Err(::rustical_xml::XmlError::UnsupportedEvent("Processing instruction"));
|
||||
}
|
||||
Event::DocType(doctype) => {
|
||||
return Err(::rustical_xml::XmlDeError::UnsupportedEvent("Doctype in the middle of the document"));
|
||||
return Err(::rustical_xml::XmlError::UnsupportedEvent("Doctype in the middle of the document"));
|
||||
}
|
||||
Event::End(end) => {
|
||||
return Err(::rustical_xml::XmlDeError::UnsupportedEvent("Premature end"));
|
||||
return Err(::rustical_xml::XmlError::UnsupportedEvent("Premature end"));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ fn invalid_field_branch(ident: &syn::Ident, allow: bool) -> proc_macro2::TokenSt
|
||||
quote! {}
|
||||
} else {
|
||||
quote! {
|
||||
return Err(XmlDeError::InvalidFieldName(#ident, format!("[{ns:?}]{tag}", tag = String::from_utf8_lossy(tag)))) }
|
||||
return Err(XmlError::InvalidFieldName(#ident, format!("[{ns:?}]{tag}", tag = String::from_utf8_lossy(tag)))) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,9 +130,9 @@ impl NamedStruct {
|
||||
reader: &mut quick_xml::NsReader<R>,
|
||||
start: &quick_xml::events::BytesStart,
|
||||
empty: bool
|
||||
) -> Result<Self, rustical_xml::XmlDeError> {
|
||||
) -> Result<Self, rustical_xml::XmlError> {
|
||||
use quick_xml::events::Event;
|
||||
use rustical_xml::XmlDeError;
|
||||
use rustical_xml::XmlError;
|
||||
|
||||
let mut buf = Vec::new();
|
||||
|
||||
@@ -163,7 +163,7 @@ impl NamedStruct {
|
||||
Event::End(e) if e.name() == start.name() => {
|
||||
break;
|
||||
}
|
||||
Event::Eof => return Err(XmlDeError::Eof),
|
||||
Event::Eof => return Err(XmlError::Eof),
|
||||
// start of a child element
|
||||
Event::Start(start) | Event::Empty(start) => {
|
||||
let empty = matches!(event, Event::Empty(_));
|
||||
@@ -179,24 +179,24 @@ impl NamedStruct {
|
||||
#(#text_field_branches)*
|
||||
}
|
||||
Event::CData(cdata) => {
|
||||
return Err(XmlDeError::UnsupportedEvent("CDATA"));
|
||||
return Err(XmlError::UnsupportedEvent("CDATA"));
|
||||
}
|
||||
Event::Comment(_) => { /* ignore */ }
|
||||
Event::Decl(_) => {
|
||||
// Error: not supported
|
||||
return Err(XmlDeError::UnsupportedEvent("Declaration"));
|
||||
return Err(XmlError::UnsupportedEvent("Declaration"));
|
||||
}
|
||||
Event::PI(_) => {
|
||||
// Error: not supported
|
||||
return Err(XmlDeError::UnsupportedEvent("Processing instruction"));
|
||||
return Err(XmlError::UnsupportedEvent("Processing instruction"));
|
||||
}
|
||||
Event::DocType(doctype) => {
|
||||
// Error: start of new document
|
||||
return Err(XmlDeError::UnsupportedEvent("Doctype in the middle of the document"));
|
||||
return Err(XmlError::UnsupportedEvent("Doctype in the middle of the document"));
|
||||
}
|
||||
Event::End(end) => {
|
||||
// Error: premature end
|
||||
return Err(XmlDeError::Other("Unexpected closing tag for wrong element".to_owned()));
|
||||
return Err(XmlError::Other("Unexpected closing tag for wrong element".to_owned()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ use std::io::BufRead;
|
||||
pub use xml_derive::XmlDeserialize;
|
||||
pub use xml_derive::XmlDocument;
|
||||
|
||||
use crate::XmlDeError;
|
||||
use crate::XmlError;
|
||||
use crate::XmlRootTag;
|
||||
|
||||
pub trait XmlDeserialize: Sized {
|
||||
@@ -12,14 +12,14 @@ pub trait XmlDeserialize: Sized {
|
||||
reader: &mut quick_xml::NsReader<R>,
|
||||
start: &BytesStart,
|
||||
empty: bool,
|
||||
) -> Result<Self, XmlDeError>;
|
||||
) -> Result<Self, XmlError>;
|
||||
}
|
||||
|
||||
pub trait XmlDocument: XmlDeserialize {
|
||||
fn parse<R: BufRead>(reader: quick_xml::NsReader<R>) -> Result<Self, XmlDeError>;
|
||||
fn parse<R: BufRead>(reader: quick_xml::NsReader<R>) -> Result<Self, XmlError>;
|
||||
|
||||
#[inline]
|
||||
fn parse_reader<R: BufRead>(input: R) -> Result<Self, XmlDeError>
|
||||
fn parse_reader<R: BufRead>(input: R) -> Result<Self, XmlError>
|
||||
where
|
||||
Self: XmlDeserialize,
|
||||
{
|
||||
@@ -29,13 +29,13 @@ pub trait XmlDocument: XmlDeserialize {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn parse_str(s: &str) -> Result<Self, XmlDeError> {
|
||||
fn parse_str(s: &str) -> Result<Self, XmlError> {
|
||||
Self::parse_reader(s.as_bytes())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: XmlRootTag + XmlDeserialize> XmlDocument for T {
|
||||
fn parse<R: BufRead>(mut reader: quick_xml::NsReader<R>) -> Result<Self, XmlDeError>
|
||||
fn parse<R: BufRead>(mut reader: quick_xml::NsReader<R>) -> Result<Self, XmlError>
|
||||
where
|
||||
Self: XmlDeserialize,
|
||||
{
|
||||
@@ -57,7 +57,7 @@ impl<T: XmlRootTag + XmlDeserialize> XmlDocument for T {
|
||||
};
|
||||
if !matches {
|
||||
let root_ns = Self::root_ns();
|
||||
return Err(XmlDeError::InvalidTag(
|
||||
return Err(XmlError::InvalidTag(
|
||||
format!("{ns:?}"),
|
||||
String::from_utf8_lossy(name.as_ref()).to_string(),
|
||||
format!("{root_ns:?}"),
|
||||
@@ -67,7 +67,7 @@ impl<T: XmlRootTag + XmlDeserialize> XmlDocument for T {
|
||||
|
||||
return Self::deserialize(&mut reader, &start, empty);
|
||||
}
|
||||
_ => return Err(XmlDeError::UnsupportedEvent("unknown, todo")),
|
||||
_ => return Err(XmlError::UnsupportedEvent("unknown, todo")),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum XmlDeError {
|
||||
pub enum XmlError {
|
||||
#[error(transparent)]
|
||||
QuickXmlError(#[from] quick_xml::Error),
|
||||
#[error(transparent)]
|
||||
|
||||
@@ -10,7 +10,7 @@ mod value;
|
||||
|
||||
pub use de::XmlDeserialize;
|
||||
pub use de::XmlDocument;
|
||||
pub use error::XmlDeError;
|
||||
pub use error::XmlError;
|
||||
pub use se::XmlSerialize;
|
||||
pub use se::XmlSerializeRoot;
|
||||
pub use value::{ParseValueError, ValueDeserialize, ValueSerialize};
|
||||
@@ -21,7 +21,7 @@ impl XmlDeserialize for () {
|
||||
reader: &mut quick_xml::NsReader<R>,
|
||||
start: &BytesStart,
|
||||
empty: bool,
|
||||
) -> Result<Self, XmlDeError> {
|
||||
) -> Result<Self, XmlError> {
|
||||
if empty {
|
||||
return Ok(());
|
||||
}
|
||||
@@ -29,7 +29,7 @@ impl XmlDeserialize for () {
|
||||
loop {
|
||||
match reader.read_event_into(&mut buf)? {
|
||||
Event::End(e) if e.name() == start.name() => return Ok(()),
|
||||
Event::Eof => return Err(XmlDeError::Eof),
|
||||
Event::Eof => return Err(XmlError::Eof),
|
||||
_ => {}
|
||||
};
|
||||
}
|
||||
@@ -91,7 +91,7 @@ impl XmlDeserialize for Unparsed {
|
||||
reader: &mut quick_xml::NsReader<R>,
|
||||
start: &BytesStart,
|
||||
empty: bool,
|
||||
) -> Result<Self, XmlDeError> {
|
||||
) -> Result<Self, XmlError> {
|
||||
// let reader_cloned = NsReader::from_reader(reader.get_ref().to_owned());
|
||||
if !empty {
|
||||
let mut buf = vec![];
|
||||
|
||||
@@ -5,7 +5,7 @@ use std::num::{ParseFloatError, ParseIntError};
|
||||
use std::{convert::Infallible, io::BufRead};
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::{XmlDeError, XmlDeserialize, XmlSerialize};
|
||||
use crate::{XmlError, XmlDeserialize, XmlSerialize};
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum ParseValueError {
|
||||
@@ -22,7 +22,7 @@ pub trait ValueSerialize: Sized {
|
||||
}
|
||||
|
||||
pub trait ValueDeserialize: Sized {
|
||||
fn deserialize(val: &str) -> Result<Self, XmlDeError>;
|
||||
fn deserialize(val: &str) -> Result<Self, XmlError>;
|
||||
}
|
||||
|
||||
macro_rules! impl_value_parse {
|
||||
@@ -34,10 +34,10 @@ macro_rules! impl_value_parse {
|
||||
}
|
||||
|
||||
impl ValueDeserialize for $t {
|
||||
fn deserialize(val: &str) -> Result<Self, XmlDeError> {
|
||||
fn deserialize(val: &str) -> Result<Self, XmlError> {
|
||||
val.parse()
|
||||
.map_err(ParseValueError::from)
|
||||
.map_err(XmlDeError::from)
|
||||
.map_err(XmlError::from)
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -68,7 +68,7 @@ impl<T: ValueDeserialize> XmlDeserialize for T {
|
||||
reader: &mut quick_xml::NsReader<R>,
|
||||
_start: &BytesStart,
|
||||
empty: bool,
|
||||
) -> Result<Self, XmlDeError> {
|
||||
) -> Result<Self, XmlError> {
|
||||
let mut string = String::new();
|
||||
|
||||
if !empty {
|
||||
@@ -78,13 +78,13 @@ impl<T: ValueDeserialize> XmlDeserialize for T {
|
||||
Event::Text(text) => {
|
||||
if !string.is_empty() {
|
||||
// Content already written
|
||||
return Err(XmlDeError::UnsupportedEvent("content already written"));
|
||||
return Err(XmlError::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")),
|
||||
Event::Eof => return Err(XmlError::Eof),
|
||||
_ => return Err(XmlError::UnsupportedEvent("todo")),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user