mago_type_syntax/ast/
variable.rs

1use serde::Serialize;
2
3use mago_span::HasSpan;
4use mago_span::Span;
5
6use crate::token::TypeToken;
7use crate::token::TypeTokenKind;
8
9#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, Serialize, PartialOrd, Ord)]
10pub struct VariableType<'input> {
11    pub span: Span,
12    pub value: &'input str,
13}
14
15impl HasSpan for VariableType<'_> {
16    fn span(&self) -> Span {
17        self.span
18    }
19}
20
21impl<'input> From<TypeToken<'input>> for VariableType<'input> {
22    #[inline]
23    fn from(token: TypeToken<'input>) -> Self {
24        debug_assert_eq!(token.kind, TypeTokenKind::Variable);
25
26        VariableType { span: token.span, value: token.value }
27    }
28}
29
30impl std::fmt::Display for VariableType<'_> {
31    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
32        write!(f, "{}", self.value)
33    }
34}