disco: Use a macro for <identity/>.
This commit is contained in:
parent
c4d867571e
commit
b56582c8b5
2 changed files with 40 additions and 61 deletions
|
|
@ -33,6 +33,25 @@ macro_rules! get_attr {
|
|||
}
|
||||
}
|
||||
};
|
||||
($elem:ident, $attr:tt, RequiredNonEmpty, $value:ident, $func:expr) => {
|
||||
match $elem.attr($attr) {
|
||||
Some("") => {
|
||||
return Err(crate::util::error::Error::ParseError(concat!(
|
||||
"Required attribute '",
|
||||
$attr,
|
||||
"' must not be empty."
|
||||
)));
|
||||
},
|
||||
Some($value) => $func,
|
||||
None => {
|
||||
return Err(crate::util::error::Error::ParseError(concat!(
|
||||
"Required attribute '",
|
||||
$attr,
|
||||
"' missing."
|
||||
)));
|
||||
}
|
||||
}
|
||||
};
|
||||
($elem:ident, $attr:tt, Default, $value:ident, $func:expr) => {
|
||||
match $elem.attr($attr) {
|
||||
Some($value) => $func,
|
||||
|
|
@ -408,6 +427,9 @@ macro_rules! decl_attr {
|
|||
(Required, $type:ty) => (
|
||||
$type
|
||||
);
|
||||
(RequiredNonEmpty, $type:ty) => (
|
||||
$type
|
||||
);
|
||||
(Default, $type:ty) => (
|
||||
$type
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in a new issue