mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 01:12:24 +00:00
xml: Some restructuring
This commit is contained in:
@@ -28,7 +28,8 @@ pub struct VariantAttrs {
|
||||
#[darling(attributes(xml))]
|
||||
pub struct EnumAttrs {
|
||||
#[darling(flatten)]
|
||||
pub container: ContainerAttrs,
|
||||
// TODO: implement ns_strict
|
||||
pub _container: ContainerAttrs,
|
||||
pub untagged: Flag,
|
||||
}
|
||||
|
||||
|
||||
16
crates/xml/derive/src/common.rs
Normal file
16
crates/xml/derive/src/common.rs
Normal file
@@ -0,0 +1,16 @@
|
||||
pub(crate) fn get_generic_type(ty: &syn::Type) -> Option<&syn::Type> {
|
||||
if let syn::Type::Path(syn::TypePath { path, .. }) = ty {
|
||||
if let Some(seg) = path.segments.last() {
|
||||
if let syn::PathArguments::AngleBracketed(syn::AngleBracketedGenericArguments {
|
||||
args,
|
||||
..
|
||||
}) = &seg.arguments
|
||||
{
|
||||
if let Some(syn::GenericArgument::Type(t)) = &args.first() {
|
||||
return Some(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
@@ -324,7 +324,7 @@ impl Field {
|
||||
(FieldType::Untagged, false) => Some(quote! {
|
||||
#serializer(&self.#target_field_index, None, None, namespaces, writer)?;
|
||||
}),
|
||||
// TODO: Think about what to do here
|
||||
// We ignore this :)
|
||||
(FieldType::TagName | FieldType::Namespace, _) => None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,33 +2,18 @@ use core::panic;
|
||||
use syn::{parse_macro_input, DeriveInput};
|
||||
|
||||
pub(crate) mod attrs;
|
||||
mod common;
|
||||
mod field;
|
||||
mod variant;
|
||||
mod xml_enum;
|
||||
mod xml_struct;
|
||||
|
||||
pub(crate) use common::*;
|
||||
pub(crate) use field::Field;
|
||||
pub(crate) use variant::Variant;
|
||||
pub(crate) use xml_enum::Enum;
|
||||
pub(crate) use xml_struct::NamedStruct;
|
||||
|
||||
pub(crate) fn get_generic_type(ty: &syn::Type) -> Option<&syn::Type> {
|
||||
if let syn::Type::Path(syn::TypePath { path, .. }) = ty {
|
||||
if let Some(seg) = path.segments.last() {
|
||||
if let syn::PathArguments::AngleBracketed(syn::AngleBracketedGenericArguments {
|
||||
args,
|
||||
..
|
||||
}) = &seg.arguments
|
||||
{
|
||||
if let Some(syn::GenericArgument::Type(t)) = &args.first() {
|
||||
return Some(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
#[proc_macro_derive(XmlDeserialize, attributes(xml))]
|
||||
pub fn derive_xml_deserialize(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
||||
let input = parse_macro_input!(input as DeriveInput);
|
||||
|
||||
Reference in New Issue
Block a user