Skip to main content

microcad_lang/syntax/
type_annotation.rs

1// Copyright © 2025-2026 The µcad authors <info@microcad.xyz>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4//! µcad Type annotation.
5
6use microcad_lang_base::{Refer, SrcRef, SrcReferrer, TreeDisplay, TreeState};
7
8use crate::ty::*;
9
10/// Type within source code.
11#[derive(Clone, PartialEq)]
12pub struct TypeAnnotation(pub Refer<Type>);
13
14impl SrcReferrer for TypeAnnotation {
15    fn src_ref(&self) -> SrcRef {
16        self.0.src_ref()
17    }
18}
19
20impl std::fmt::Display for TypeAnnotation {
21    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
22        self.0.fmt(f)
23    }
24}
25
26impl std::fmt::Debug for TypeAnnotation {
27    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
28        write!(f, "{:?}", self.0)
29    }
30}
31
32impl crate::ty::Ty for TypeAnnotation {
33    fn ty(&self) -> Type {
34        self.0.value.clone()
35    }
36}
37
38impl TreeDisplay for TypeAnnotation {
39    fn tree_print(&self, f: &mut std::fmt::Formatter, depth: TreeState) -> std::fmt::Result {
40        writeln!(f, "{:depth$}TypeAnnotation: {}", "", self.0.value)
41    }
42}