minicas_core/ast/
node_const.rs1use crate::{Ty, TyValue};
2use std::fmt;
3
4#[derive(Debug, Clone, PartialEq, Eq, Hash)]
6pub struct Const(pub(crate) TyValue);
7
8impl Const {
9 pub fn new<V: Into<TyValue>>(val: V) -> Self {
11 Self(val.into())
12 }
13
14 pub fn returns(&self) -> Ty {
16 return self.0.ty();
17 }
18
19 pub fn value(&self) -> &TyValue {
21 &self.0
22 }
23}
24
25impl<T: Into<TyValue>> From<T> for Const {
26 fn from(input: T) -> Const {
27 Const(input.into())
28 }
29}
30
31impl fmt::Display for Const {
32 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
33 fmt::Display::fmt(&self.0, f)
34 }
35}