prjunnamed_netlist/
param.rs

1use crate::{Const, Design, Trit};
2use std::fmt::Display;
3
4#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
5pub enum ParamValue {
6    Const(Const),
7    Int(i64),
8    Float(u64),
9    String(String),
10}
11
12impl From<bool> for ParamValue {
13    fn from(value: bool) -> Self {
14        Self::Const(Trit::from(value).into())
15    }
16}
17
18impl From<Trit> for ParamValue {
19    fn from(value: Trit) -> Self {
20        Self::Const(value.into())
21    }
22}
23
24impl From<Const> for ParamValue {
25    fn from(value: Const) -> Self {
26        Self::Const(value)
27    }
28}
29
30impl From<&Const> for ParamValue {
31    fn from(value: &Const) -> Self {
32        Self::Const(value.clone())
33    }
34}
35
36impl From<i64> for ParamValue {
37    fn from(value: i64) -> Self {
38        Self::Int(value)
39    }
40}
41
42impl From<String> for ParamValue {
43    fn from(value: String) -> Self {
44        Self::String(value)
45    }
46}
47
48impl From<&str> for ParamValue {
49    fn from(value: &str) -> Self {
50        Self::String(value.into())
51    }
52}
53
54impl Display for ParamValue {
55    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
56        match self {
57            ParamValue::Const(value) => write!(f, "{value}"),
58            ParamValue::Int(value) => write!(f, "#{value}"),
59            ParamValue::Float(_value) => unimplemented!("float parameter"),
60            ParamValue::String(value) => Design::write_string(f, &value),
61        }
62    }
63}