use serde::Serialize;
use mago_database::file::FileId;
use mago_span::HasSpan;
use mago_span::Span;
use crate::token::TypeToken;
use crate::token::TypeTokenKind;
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, Serialize, PartialOrd, Ord)]
pub struct VariableType<'arena> {
pub span: Span,
pub value: &'arena [u8],
}
impl HasSpan for VariableType<'_> {
fn span(&self) -> Span {
self.span
}
}
impl<'arena> VariableType<'arena> {
#[inline]
#[must_use]
pub fn from_token(token: TypeToken<'arena>, file_id: FileId) -> Self {
debug_assert_eq!(token.kind, TypeTokenKind::Variable, "expected a Variable token");
VariableType { span: token.span_for(file_id), value: token.value }
}
}
impl std::fmt::Display for VariableType<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(&String::from_utf8_lossy(self.value))
}
}