mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 04:42:15 +00:00
dav: Refactor proppatch, remove InvalidProperty trait
This commit is contained in:
@@ -5,11 +5,13 @@ use darling::FromDeriveInput;
|
||||
use quote::quote;
|
||||
use syn::{DataStruct, DeriveInput};
|
||||
|
||||
fn invalid_field_branch(allow: bool) -> proc_macro2::TokenStream {
|
||||
fn invalid_field_branch(ident: &syn::Ident, allow: bool) -> proc_macro2::TokenStream {
|
||||
let ident = ident.to_string();
|
||||
if allow {
|
||||
quote! {}
|
||||
} else {
|
||||
quote! { return Err(XmlDeError::InvalidFieldName(format!("[{ns:?}]{tag}", tag = String::from_utf8_lossy(tag)))) }
|
||||
quote! {
|
||||
return Err(XmlDeError::InvalidFieldName(#ident, format!("[{ns:?}]{tag}", tag = String::from_utf8_lossy(tag)))) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,7 +87,8 @@ impl NamedStruct {
|
||||
|
||||
let builder_field_builds = self.fields.iter().map(Field::builder_field_build);
|
||||
|
||||
let invalid_field_branch = invalid_field_branch(self.attrs.allow_invalid.is_present());
|
||||
let invalid_field_branch =
|
||||
invalid_field_branch(ident, self.attrs.allow_invalid.is_present());
|
||||
|
||||
quote! {
|
||||
impl #impl_generics ::rustical_xml::XmlDeserialize for #ident #type_generics #where_clause {
|
||||
|
||||
@@ -28,8 +28,8 @@ pub enum XmlDeError {
|
||||
Other(String),
|
||||
#[error("Invalid variant: {0}")]
|
||||
InvalidVariant(String),
|
||||
#[error("Invalid field name: {0}")]
|
||||
InvalidFieldName(String),
|
||||
#[error("Invalid field name in {0}: {1}")]
|
||||
InvalidFieldName(&'static str, String),
|
||||
#[error(transparent)]
|
||||
InvalidValue(#[from] crate::value::ParseValueError),
|
||||
}
|
||||
|
||||
@@ -36,6 +36,13 @@ impl XmlDeserialize for () {
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct Unparsed(BytesStart<'static>);
|
||||
|
||||
impl Unparsed {
|
||||
pub fn tag_name(&self) -> String {
|
||||
// TODO: respect namespace?
|
||||
String::from_utf8_lossy(self.0.local_name().as_ref()).to_string()
|
||||
}
|
||||
}
|
||||
|
||||
impl XmlDeserialize for Unparsed {
|
||||
fn deserialize<R: BufRead>(
|
||||
reader: &mut quick_xml::NsReader<R>,
|
||||
|
||||
Reference in New Issue
Block a user