boseiju/lexer/tokens/intermediates/
keyword_ability.rs

1use crate::lexer::IntoToken;
2
3/// Wrapper around the keyword ability.
4#[derive(serde::Serialize, serde::Deserialize)]
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
6pub struct KeywordAbility {
7    pub keyword_ability: mtg_data::KeywordAbility,
8    #[cfg(feature = "spanned_tree")]
9    pub span: crate::ability_tree::span::TreeSpan,
10}
11
12#[cfg(feature = "lexer")]
13impl IntoToken for KeywordAbility {
14    fn try_from_span(span: &crate::lexer::Span) -> Option<Self> {
15        use std::str::FromStr;
16        Some(Self {
17            keyword_ability: mtg_data::KeywordAbility::from_str(&span.text).ok()?,
18            #[cfg(feature = "spanned_tree")]
19            span: span.into(),
20        })
21    }
22}
23
24impl idris::Idris for KeywordAbility {
25    const COUNT: usize = mtg_data::KeywordAbility::COUNT;
26    fn id(&self) -> usize {
27        self.keyword_ability.id()
28    }
29    fn name_from_id(id: usize) -> &'static str {
30        mtg_data::KeywordAbility::name_from_id(id)
31    }
32}