roster: Make Group a proper struct.
This commit is contained in:
parent
5388696b95
commit
6ec1e46953
2 changed files with 33 additions and 7 deletions
22
src/lib.rs
22
src/lib.rs
|
|
@ -144,6 +144,28 @@ macro_rules! generate_id {
|
|||
);
|
||||
}
|
||||
|
||||
macro_rules! generate_elem_id {
|
||||
($elem:ident, $name:tt, $ns:expr) => (
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct $elem(pub String);
|
||||
impl FromStr for $elem {
|
||||
type Err = Error;
|
||||
fn from_str(s: &str) -> Result<$elem, Error> {
|
||||
// TODO: add a way to parse that differently when needed.
|
||||
Ok($elem(String::from(s)))
|
||||
}
|
||||
}
|
||||
impl From<$elem> for Element {
|
||||
fn from(elem: $elem) -> Element {
|
||||
Element::builder($name)
|
||||
.ns($ns)
|
||||
.append(elem.0)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/// Error type returned by every parser on failure.
|
||||
pub mod error;
|
||||
/// XML namespace definitions used through XMPP.
|
||||
|
|
|
|||
Loading…
Reference in a new issue