mago_codex/metadata/
constant.rs1use serde::Deserialize;
2use serde::Serialize;
3
4use mago_interner::StringIdentifier;
5use mago_reporting::Issue;
6use mago_span::HasSpan;
7use mago_span::Span;
8
9use crate::metadata::attribute::AttributeMetadata;
10use crate::ttype::union::TUnion;
11
12#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
17pub struct ConstantMetadata {
18 pub attributes: Vec<AttributeMetadata>,
19 pub name: StringIdentifier,
20 pub span: Span,
21 pub inferred_type: Option<TUnion>,
22 pub is_deprecated: bool,
23 pub is_internal: bool,
24 pub user_defined: bool,
25 pub issues: Vec<Issue>,
26}
27
28impl ConstantMetadata {
29 #[inline]
36 pub fn new(name: StringIdentifier, span: Span) -> Self {
37 Self {
38 attributes: Vec::new(),
39 name,
40 span,
41 inferred_type: None,
42 is_deprecated: false,
43 is_internal: false,
44 user_defined: span.start.source.category().is_user_defined(),
45 issues: Vec::new(),
46 }
47 }
48
49 #[inline]
51 pub fn take_issues(&mut self) -> Vec<Issue> {
52 std::mem::take(&mut self.issues)
53 }
54}
55
56impl HasSpan for ConstantMetadata {
57 fn span(&self) -> Span {
58 self.span
59 }
60}