xmelt 0.2.0

A serialization/deserialization framework for XML
Documentation
#[derive(Debug)]
pub struct QName<'a> {
	namespace: Option<&'a str>,
	name: &'a str,
}

impl<'a> QName<'a> {
	pub fn new(namespace: Option<&'a str>, name: &'a str) -> Self {
		Self {
			namespace,
			name,
		}
	}

	pub fn eq(&self, namespace: Option<&'a str>, name: &'a str) -> bool {
		self.namespace == namespace && self.name == name
	}

	pub fn tuple(&self) -> (Option<&'a str>, &'a str) {
		(self.namespace, self.name)
	}

	pub fn fmt_qname(&self) -> String {
		if let Some(ns) = self.namespace {
			format!("{}:{}", ns, self.name)
		} else {
			self.name.to_owned()
		}
	}
}

impl<'a> From<(Option<&'a str>, &'a str)> for QName<'a> {
	fn from(a: (Option<&'a str>, &'a str)) -> Self {
		Self {
			namespace: a.0,
			name: a.1
		}
	}
}



impl<'a> From<roxmltree::ExpandedName<'a, 'a>> for QName<'a> {
	fn from(a: roxmltree::ExpandedName<'a, 'a>) -> Self {
		Self {
			namespace: a.namespace(),
			name: a.name(),
		}
	}
}

pub fn fmt_qname(ns: Option<&str>, name: &str) -> String {
	if let Some(ns) = ns {
		format!("{ns}:{name}")
	} else {
		name.to_owned()
	}
}