From 29fb6d5a9e21bf328906a44a6a31cd1b6f2300ee Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Fri, 2 Sep 2022 21:53:35 +0200 Subject: [PATCH] Rename namespace to ns in attributes This more closely mimics the way xmlns gets used in XML in addition to being more concise. --- instant-xml-macros/src/lib.rs | 4 +-- instant-xml/tests/all.rs | 56 +++++++++++++++++------------------ 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/instant-xml-macros/src/lib.rs b/instant-xml-macros/src/lib.rs index f750f58..5f206db 100644 --- a/instant-xml-macros/src/lib.rs +++ b/instant-xml-macros/src/lib.rs @@ -95,7 +95,7 @@ impl ContainerMeta { let mut meta = ContainerMeta::default(); for item in meta_items(&input.attrs) { match item { - Meta::List(list) if list.path.is_ident("namespace") => { + Meta::List(list) if list.path.is_ident("ns") => { meta.ns = NamespaceMeta::from_list(&list.nested) } _ => panic!("invalid xml attribute syntax"), @@ -117,7 +117,7 @@ impl FieldMeta { for item in meta_items(&input.attrs) { match item { Meta::Path(path) if path.is_ident("attribute") => meta.attribute = true, - Meta::List(list) if list.path.is_ident("namespace") => { + Meta::List(list) if list.path.is_ident("ns") => { meta.ns = NamespaceMeta::from_list(&list.nested) } _ => panic!("invalid xml attribute syntax"), diff --git a/instant-xml/tests/all.rs b/instant-xml/tests/all.rs index bd72de9..68e044a 100644 --- a/instant-xml/tests/all.rs +++ b/instant-xml/tests/all.rs @@ -12,12 +12,12 @@ fn unit() { } #[derive(Debug, Eq, PartialEq, ToXml)] -#[xml(namespace(bar = "BAZ", foo = "BAR"))] +#[xml(ns(bar = "BAZ", foo = "BAR"))] struct StructWithNamedFields { flag: bool, - #[xml(namespace(bar))] + #[xml(ns(bar))] string: String, - #[xml(namespace("typo"))] + #[xml(ns("typo"))] number: i32, } @@ -41,24 +41,24 @@ fn struct_with_named_fields() { } #[derive(Debug, Eq, PartialEq, ToXml)] -#[xml(namespace("URI", dar = "BAZ", internal = "INTERNAL"))] +#[xml(ns("URI", dar = "BAZ", internal = "INTERNAL"))] struct Nested { - #[xml(namespace(dar))] + #[xml(ns(dar))] flag_parent_prefix: bool, - #[xml(namespace(internal))] + #[xml(ns(internal))] flag_internal_prefix: bool, } #[derive(Debug, Eq, PartialEq, ToXml)] -#[xml(namespace("URI", bar = "BAZ", foo = "BAR"))] +#[xml(ns("URI", bar = "BAZ", foo = "BAR"))] struct StructWithCustomField { #[xml(attribute)] int_attribute: i32, - #[xml(namespace("BAZ"))] + #[xml(ns("BAZ"))] flag_direct_namespace_same_the_same_as_prefix: bool, - #[xml(namespace(bar))] + #[xml(ns(bar))] flag_prefix: bool, - #[xml(namespace("DIFFERENT"))] + #[xml(ns("DIFFERENT"))] flag_direct_namespace: bool, test: Nested, } @@ -92,16 +92,16 @@ fn struct_with_custom_field() { } #[derive(Debug, Eq, PartialEq, ToXml)] -#[xml(namespace(dar = "BAZ", internal = "INTERNAL"))] +#[xml(ns(dar = "BAZ", internal = "INTERNAL"))] struct NestedDifferentNamespace { - #[xml(namespace(dar))] + #[xml(ns(dar))] flag_parent_prefix: bool, - #[xml(namespace(internal))] + #[xml(ns(internal))] flag_internal_prefix: bool, } #[derive(Debug, Eq, PartialEq, ToXml)] -#[xml(namespace("URI", bar = "BAZ", foo = "BAR"))] +#[xml(ns("URI", bar = "BAZ", foo = "BAR"))] struct StructChildNamespaces { different_child_namespace: NestedDifferentNamespace, same_child_namespace: Nested, @@ -130,16 +130,16 @@ fn struct_child_namespaces() { } #[derive(Debug, Eq, PartialEq, FromXml)] -#[xml(namespace("URI", bar = "BAZ"))] +#[xml(ns("URI", bar = "BAZ"))] struct NestedDe { - #[xml(namespace(bar))] + #[xml(ns(bar))] flag: bool, } #[derive(Debug, Eq, PartialEq, FromXml)] -#[xml(namespace("URI", bar = "BAZ", foo = "BAR"))] +#[xml(ns("URI", bar = "BAZ", foo = "BAR"))] struct StructWithCustomFieldFromXml { - #[xml(namespace(bar))] + #[xml(ns(bar))] flag: bool, #[xml(attribute)] flag_attribute: bool, @@ -191,13 +191,13 @@ struct NestedWrongNamespace { } #[derive(Debug, Eq, PartialEq, FromXml)] -#[xml(namespace("URI", bar = "BAZ"))] +#[xml(ns("URI", bar = "BAZ"))] struct StructWithCorrectNestedNamespace { test: NestedDe, } #[derive(Debug, Eq, PartialEq, FromXml)] -#[xml(namespace("URI", bar = "BAZ"))] +#[xml(ns("URI", bar = "BAZ"))] struct StructWithWrongNestedNamespace { test: NestedWrongNamespace, } @@ -256,14 +256,14 @@ fn default_namespaces() { } #[derive(Debug, Eq, PartialEq, FromXml)] -#[xml(namespace("URI", bar = "BAZ"))] +#[xml(ns("URI", bar = "BAZ"))] struct NestedOtherNamespace { - #[xml(namespace(bar))] + #[xml(ns(bar))] flag: bool, } #[derive(Debug, Eq, PartialEq, FromXml)] -#[xml(namespace("URI", bar = "BAZ"))] +#[xml(ns("URI", bar = "BAZ"))] struct StructOtherNamespace { test: NestedOtherNamespace, } @@ -343,9 +343,9 @@ fn other_namespaces() { } #[derive(Debug, Eq, PartialEq, FromXml)] -#[xml(namespace("URI"))] +#[xml(ns("URI"))] struct StructDirectNamespace { - #[xml(namespace("BAZ"))] + #[xml(ns("BAZ"))] flag: bool, } @@ -380,14 +380,14 @@ fn direct_namespaces() { } #[derive(Debug, PartialEq, Eq, FromXml, ToXml)] -#[xml(namespace("URI"))] +#[xml(ns("URI"))] struct NestedLifetimes<'a> { flag: bool, str_type_a: &'a str, } #[derive(Debug, PartialEq, FromXml, ToXml)] -#[xml(namespace("URI"))] +#[xml(ns("URI"))] struct StructDeserializerScalars<'a, 'b> { bool_type: bool, i8_type: i8, @@ -452,7 +452,7 @@ fn scalars() { } #[derive(Debug, PartialEq, Eq, FromXml, ToXml)] -#[xml(namespace("URI"))] +#[xml(ns("URI"))] struct StructSpecialEntities<'a> { string: String, str: &'a str,