mago_type_syntax/ast/
variable.rs1use serde::Serialize;
2
3use mago_database::file::FileId;
4use mago_span::HasSpan;
5use mago_span::Span;
6
7use crate::token::TypeToken;
8use crate::token::TypeTokenKind;
9
10#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, Serialize, PartialOrd, Ord)]
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> VariableType<'input> {
23 #[inline]
25 pub fn from_token(token: TypeToken<'input>, file_id: FileId) -> Self {
26 debug_assert_eq!(token.kind, TypeTokenKind::Variable);
27
28 VariableType { span: token.span_for(file_id), value: token.value }
29 }
30}
31
32impl std::fmt::Display for VariableType<'_> {
33 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
34 write!(f, "{}", self.value)
35 }
36}