use weedle::interface::OperationInterfaceMember;
use weedle::mixin::OperationMixinMember;
use weedle::namespace::OperationNamespaceMember;
pub trait SymbolWithOptionalIdentifier<'a> {
fn identifier(&self) -> Option<weedle::common::Identifier<'a>>;
fn has_identifier(&self) -> bool;
}
macro_rules! impl_symbol_with_optional_identifier {
($($sym:ident),+ $(,)?) => {
$(
impl<'a> SymbolWithOptionalIdentifier<'a> for $sym<'a> {
fn identifier(&self) -> Option<weedle::common::Identifier<'a>> {
self.identifier
}
fn has_identifier(&self) -> bool {
self.identifier.is_some()
}
}
)+
};
}
impl_symbol_with_optional_identifier!(
OperationInterfaceMember,
OperationMixinMember,
OperationNamespaceMember,
);
#[cfg(test)]
mod tests {
use crate::symbol::SymbolWithOptionalIdentifier;
use weedle::common::Identifier;
use weedle::interface::OperationInterfaceMember;
use weedle::Parse;
#[test]
fn test_operation_interface_member() {
let (_, output) = OperationInterfaceMember::parse(
"static Promise<boolean> isTypeSupported(DOMString type);",
)
.expect("OperationInterfaceMember parsed with an error");
assert_eq!(output.identifier(), Some(Identifier("isTypeSupported")));
assert!(output.has_identifier());
}
}