Get active features dynamically by their `Symbol`

This commit is contained in:
Dylan MacKenzie 2019-12-10 12:41:27 -08:00
parent 3964a55ba5
commit 8f3021bd2c
1 changed files with 12 additions and 0 deletions

View File

@ -53,6 +53,18 @@ macro_rules! declare_features {
$(f(stringify!($feature), self.$feature);)+
}
}
impl std::ops::Index<Symbol> for Features {
type Output = bool;
fn index(&self, feature: Symbol) -> &Self::Output {
match feature {
$( sym::$feature => &self.$feature, )*
_ => panic!("{} was not defined in `declare_features`", feature),
}
}
}
};
}