microcad_lang/syntax/
type_annotation.rs

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