Skip to main content

namespace

Macro namespace 

Source
macro_rules! namespace {
    ($($name:ident = $uri:literal),+ $(,)?) => { ... };
}
Expand description

Defines a macro that writes names in a namespace.

namespace!(atom = "http://www.w3.org/2005/Atom") defines atom! so that atom!("title") is qname!("http://www.w3.org/2005/Atom", "title"), atom!(@ "href") the attribute and atom!() the URI. The names of the macros are the prefixes of the namespaces in prefixes!. Like all macros defined by macros, they can be used after the invocation in the same module and its children.

deser_xml::namespace!(atom = "http://www.w3.org/2005/Atom");

#[derive(deser::Deserialize)]
struct Entry {
    #[deser(rename = atom!("title"))]
    title: String,
    #[deser(rename = atom!(@ "lang"))]
    lang: Option<String>,
}

assert_eq!(atom!("title"), "{http://www.w3.org/2005/Atom}title");
assert_eq!(atom!(), "http://www.w3.org/2005/Atom");