mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 05:52:19 +00:00
xml: Rename XmlRoot to XmlRootTag
This commit is contained in:
@@ -47,7 +47,7 @@ pub struct NamedStruct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl NamedStruct {
|
impl NamedStruct {
|
||||||
pub fn impl_xml_root(&self) -> proc_macro2::TokenStream {
|
pub fn impl_xml_root_tag(&self) -> proc_macro2::TokenStream {
|
||||||
let (impl_generics, type_generics, where_clause) = self.generics.split_for_impl();
|
let (impl_generics, type_generics, where_clause) = self.generics.split_for_impl();
|
||||||
let ident = &self.ident;
|
let ident = &self.ident;
|
||||||
let root = self.attrs.root.as_ref().expect("No root attribute found");
|
let root = self.attrs.root.as_ref().expect("No root attribute found");
|
||||||
@@ -56,7 +56,7 @@ impl NamedStruct {
|
|||||||
None => quote! { None },
|
None => quote! { None },
|
||||||
};
|
};
|
||||||
quote! {
|
quote! {
|
||||||
impl #impl_generics ::rustical_xml::XmlRoot for #ident #type_generics #where_clause {
|
impl #impl_generics ::rustical_xml::XmlRootTag for #ident #type_generics #where_clause {
|
||||||
fn root_tag() -> &'static [u8] { #root }
|
fn root_tag() -> &'static [u8] { #root }
|
||||||
fn root_ns() -> Option<&'static [u8]> { #ns }
|
fn root_ns() -> Option<&'static [u8]> { #ns }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,12 +28,12 @@ pub fn derive_xml_serialize(input: proc_macro::TokenStream) -> proc_macro::Token
|
|||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[proc_macro_derive(XmlRoot, attributes(xml))]
|
#[proc_macro_derive(XmlRootTag, attributes(xml))]
|
||||||
pub fn derive_xml_root(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
pub fn derive_xml_root_tag(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
||||||
let input = parse_macro_input!(input as DeriveInput);
|
let input = parse_macro_input!(input as DeriveInput);
|
||||||
|
|
||||||
match &input.data {
|
match &input.data {
|
||||||
syn::Data::Struct(s) => NamedStruct::parse(&input, s).impl_xml_root(),
|
syn::Data::Struct(s) => NamedStruct::parse(&input, s).impl_xml_root_tag(),
|
||||||
syn::Data::Enum(_) => panic!("Enum not supported as root"),
|
syn::Data::Enum(_) => panic!("Enum not supported as root"),
|
||||||
syn::Data::Union(_) => panic!("Union not supported as root"),
|
syn::Data::Union(_) => panic!("Union not supported as root"),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use quick_xml::name::Namespace;
|
|||||||
use quick_xml::name::ResolveResult;
|
use quick_xml::name::ResolveResult;
|
||||||
use std::io::BufRead;
|
use std::io::BufRead;
|
||||||
pub use xml_derive::XmlDeserialize;
|
pub use xml_derive::XmlDeserialize;
|
||||||
pub use xml_derive::XmlRoot;
|
pub use xml_derive::XmlRootTag;
|
||||||
|
|
||||||
use quick_xml::events::{BytesStart, Event};
|
use quick_xml::events::{BytesStart, Event};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
@@ -43,7 +43,7 @@ pub trait XmlDeserialize: Sized {
|
|||||||
) -> Result<Self, XmlDeError>;
|
) -> Result<Self, XmlDeError>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait XmlRoot {
|
pub trait XmlRootTag {
|
||||||
fn root_tag() -> &'static [u8];
|
fn root_tag() -> &'static [u8];
|
||||||
fn root_ns() -> Option<&'static [u8]>;
|
fn root_ns() -> Option<&'static [u8]>;
|
||||||
}
|
}
|
||||||
@@ -67,7 +67,7 @@ pub trait XmlDocument: XmlDeserialize {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: XmlRoot + XmlDeserialize> XmlDocument for T {
|
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, XmlDeError>
|
||||||
where
|
where
|
||||||
Self: XmlDeserialize,
|
Self: XmlDeserialize,
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ mod value;
|
|||||||
|
|
||||||
pub use de::XmlDeError;
|
pub use de::XmlDeError;
|
||||||
pub use de::XmlDeserialize;
|
pub use de::XmlDeserialize;
|
||||||
pub use de::XmlRoot;
|
pub use de::XmlRootTag;
|
||||||
pub use se::XmlSerialize;
|
pub use se::XmlSerialize;
|
||||||
pub use value::Value;
|
pub use value::Value;
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
use rustical_xml::{de::XmlDocument, Unit, XmlDeserialize, XmlRoot};
|
use rustical_xml::{de::XmlDocument, Unit, XmlDeserialize, XmlRootTag};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_struct_tagged_enum() {
|
fn test_struct_tagged_enum() {
|
||||||
#[derive(Debug, XmlDeserialize, XmlRoot, PartialEq)]
|
#[derive(Debug, XmlDeserialize, XmlRootTag, PartialEq)]
|
||||||
#[xml(root = b"propfind")]
|
#[xml(root = b"propfind")]
|
||||||
struct Propfind {
|
struct Propfind {
|
||||||
prop: Prop,
|
prop: Prop,
|
||||||
@@ -57,7 +57,7 @@ fn test_struct_tagged_enum() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_tagged_enum_complex() {
|
fn test_tagged_enum_complex() {
|
||||||
#[derive(Debug, XmlDeserialize, XmlRoot, PartialEq)]
|
#[derive(Debug, XmlDeserialize, XmlRootTag, PartialEq)]
|
||||||
#[xml(root = b"propfind")]
|
#[xml(root = b"propfind")]
|
||||||
struct Propfind {
|
struct Propfind {
|
||||||
prop: PropStruct,
|
prop: PropStruct,
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
use rustical_xml::de::XmlDocument;
|
use rustical_xml::de::XmlDocument;
|
||||||
use rustical_xml::XmlRoot;
|
use rustical_xml::XmlRootTag;
|
||||||
use rustical_xml::{Unit, Unparsed, XmlDeserialize};
|
use rustical_xml::{Unit, Unparsed, XmlDeserialize};
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_struct_text_field() {
|
fn test_struct_text_field() {
|
||||||
#[derive(Debug, XmlDeserialize, XmlRoot, PartialEq)]
|
#[derive(Debug, XmlDeserialize, XmlRootTag, PartialEq)]
|
||||||
#[xml(root = b"document")]
|
#[xml(root = b"document")]
|
||||||
struct Document {
|
struct Document {
|
||||||
#[xml(ty = "text")]
|
#[xml(ty = "text")]
|
||||||
@@ -26,7 +26,7 @@ fn test_struct_text_field() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_struct_document() {
|
fn test_struct_document() {
|
||||||
#[derive(Debug, XmlDeserialize, XmlRoot, PartialEq)]
|
#[derive(Debug, XmlDeserialize, XmlRootTag, PartialEq)]
|
||||||
#[xml(root = b"document")]
|
#[xml(root = b"document")]
|
||||||
struct Document {
|
struct Document {
|
||||||
child: Child,
|
child: Child,
|
||||||
@@ -51,7 +51,7 @@ fn test_struct_document() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_struct_rename_field() {
|
fn test_struct_rename_field() {
|
||||||
#[derive(Debug, XmlDeserialize, XmlRoot, PartialEq)]
|
#[derive(Debug, XmlDeserialize, XmlRootTag, PartialEq)]
|
||||||
#[xml(root = b"document")]
|
#[xml(root = b"document")]
|
||||||
struct Document {
|
struct Document {
|
||||||
#[xml(rename = b"ok-wow")]
|
#[xml(rename = b"ok-wow")]
|
||||||
@@ -77,7 +77,7 @@ fn test_struct_rename_field() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_struct_optional_field() {
|
fn test_struct_optional_field() {
|
||||||
#[derive(Debug, XmlDeserialize, XmlRoot, PartialEq)]
|
#[derive(Debug, XmlDeserialize, XmlRootTag, PartialEq)]
|
||||||
#[xml(root = b"document")]
|
#[xml(root = b"document")]
|
||||||
struct Document {
|
struct Document {
|
||||||
#[xml(default = "Default::default")]
|
#[xml(default = "Default::default")]
|
||||||
@@ -96,7 +96,7 @@ fn test_struct_optional_field() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_struct_vec() {
|
fn test_struct_vec() {
|
||||||
#[derive(Debug, XmlDeserialize, XmlRoot, PartialEq)]
|
#[derive(Debug, XmlDeserialize, XmlRootTag, PartialEq)]
|
||||||
#[xml(root = b"document")]
|
#[xml(root = b"document")]
|
||||||
struct Document {
|
struct Document {
|
||||||
#[xml(rename = b"child", flatten)]
|
#[xml(rename = b"child", flatten)]
|
||||||
@@ -124,7 +124,7 @@ fn test_struct_vec() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_struct_set() {
|
fn test_struct_set() {
|
||||||
#[derive(Debug, XmlDeserialize, XmlRoot, PartialEq)]
|
#[derive(Debug, XmlDeserialize, XmlRootTag, PartialEq)]
|
||||||
#[xml(root = b"document")]
|
#[xml(root = b"document")]
|
||||||
struct Document {
|
struct Document {
|
||||||
#[xml(rename = b"child", flatten)]
|
#[xml(rename = b"child", flatten)]
|
||||||
@@ -152,7 +152,7 @@ fn test_struct_set() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_struct_ns() {
|
fn test_struct_ns() {
|
||||||
#[derive(Debug, XmlDeserialize, XmlRoot, PartialEq)]
|
#[derive(Debug, XmlDeserialize, XmlRootTag, PartialEq)]
|
||||||
#[xml(root = b"document", ns_strict)]
|
#[xml(root = b"document", ns_strict)]
|
||||||
struct Document {
|
struct Document {
|
||||||
#[xml(ns = b"hello")]
|
#[xml(ns = b"hello")]
|
||||||
@@ -165,7 +165,7 @@ fn test_struct_ns() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_struct_attr() {
|
fn test_struct_attr() {
|
||||||
#[derive(Debug, XmlDeserialize, XmlRoot, PartialEq)]
|
#[derive(Debug, XmlDeserialize, XmlRootTag, PartialEq)]
|
||||||
#[xml(root = b"document", ns_strict)]
|
#[xml(root = b"document", ns_strict)]
|
||||||
struct Document {
|
struct Document {
|
||||||
#[xml(ns = b"hello")]
|
#[xml(ns = b"hello")]
|
||||||
@@ -192,7 +192,7 @@ fn test_struct_attr() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_struct_generics() {
|
fn test_struct_generics() {
|
||||||
#[derive(XmlDeserialize, XmlRoot)]
|
#[derive(XmlDeserialize, XmlRootTag)]
|
||||||
#[xml(root = b"document", ns_strict)]
|
#[xml(root = b"document", ns_strict)]
|
||||||
struct Document<T: XmlDeserialize> {
|
struct Document<T: XmlDeserialize> {
|
||||||
child: T,
|
child: T,
|
||||||
@@ -212,7 +212,7 @@ fn test_struct_generics() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_struct_unparsed() {
|
fn test_struct_unparsed() {
|
||||||
#[derive(XmlDeserialize, XmlRoot)]
|
#[derive(XmlDeserialize, XmlRootTag)]
|
||||||
#[xml(root = b"document", ns_strict)]
|
#[xml(root = b"document", ns_strict)]
|
||||||
struct Document {
|
struct Document {
|
||||||
child: Unparsed,
|
child: Unparsed,
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
use rustical_xml::{XmlRoot, XmlSerialize};
|
use rustical_xml::{XmlRootTag, XmlSerialize};
|
||||||
use xml_derive::XmlDeserialize;
|
use xml_derive::XmlDeserialize;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_struct_document() {
|
fn test_struct_document() {
|
||||||
#[derive(Debug, XmlRoot, XmlSerialize, XmlDeserialize, PartialEq)]
|
#[derive(Debug, XmlRootTag, XmlSerialize, XmlDeserialize, PartialEq)]
|
||||||
#[xml(root = b"document")]
|
#[xml(root = b"document")]
|
||||||
struct Document {
|
struct Document {
|
||||||
child: Child,
|
child: Child,
|
||||||
|
|||||||
Reference in New Issue
Block a user