lib: Implement a generate_id! macro.
This commit is contained in:
parent
3ea0c45337
commit
95a19b4bb4
1 changed files with 19 additions and 0 deletions
19
src/lib.rs
19
src/lib.rs
|
@ -109,6 +109,25 @@ macro_rules! generate_attribute {
|
|||
);
|
||||
}
|
||||
|
||||
macro_rules! generate_id {
|
||||
($elem:ident) => (
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct $elem(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 IntoAttributeValue for $elem {
|
||||
fn into_attribute_value(self) -> Option<String> {
|
||||
Some(self.0)
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/// Error type returned by every parser on failure.
|
||||
pub mod error;
|
||||
/// XML namespace definitions used through XMPP.
|
||||
|
|
Loading…
Reference in a new issue