mago_type_syntax/ast/
variable.rs1use 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)]
10#[repr(C)]
11pub struct VariableType<'input> {
12 pub span: Span,
13 pub value: &'input str,
14}
15
16impl HasSpan for VariableType<'_> {
17 fn span(&self) -> Span {
18 self.span
19 }
20}
21
22impl<'input> From<TypeToken<'input>> for VariableType<'input> {
23 #[inline]
24 fn from(token: TypeToken<'input>) -> Self {
25 debug_assert_eq!(token.kind, TypeTokenKind::Variable);
26
27 VariableType { span: token.span, value: token.value }
28 }
29}
30
31impl std::fmt::Display for VariableType<'_> {
32 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
33 write!(f, "{}", self.value)
34 }
35}