webidl_utils/symbol/
with_type.rs1use weedle::argument::{SingleArgument, VariadicArgument};
2use weedle::dictionary::DictionaryMember;
3use weedle::interface::AttributeInterfaceMember;
4use weedle::mixin::AttributeMixinMember;
5use weedle::namespace::AttributeNamespaceMember;
6use weedle::types::{AttributedNonAnyType, AttributedType, NonAnyType, Type};
7use weedle::TypedefDefinition;
8
9pub trait SymbolWithType {
11 type Ty;
12 fn type_(self) -> Self::Ty;
13}
14
15macro_rules! impl_symbol_with_type {
16 ($($sym:ident | $ty:ty),+ $(,)?) => {
17 $(
18 impl<'a> SymbolWithType for $sym<'a> {
19 type Ty = $ty;
20 fn type_(self) -> Self::Ty {
21 self.type_
22 }
23 }
24 )+
25 }
26}
27
28impl_symbol_with_type!(
29 TypedefDefinition | AttributedType<'a>,
30 SingleArgument | AttributedType<'a>,
31 VariadicArgument | Type<'a>,
32 DictionaryMember | Type<'a>,
33 AttributeInterfaceMember | AttributedType<'a>,
34 AttributeMixinMember | AttributedType<'a>,
35 AttributeNamespaceMember | AttributedType<'a>,
36 AttributedType | Type<'a>,
37 AttributedNonAnyType | NonAnyType<'a>,
38);