prjunnamed_netlist/
param.rs1use crate::{Const, ConstBit, ConstSlice, Design};
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(ConstBit::from(value).into())
15 }
16}
17
18impl From<ConstBit> for ParamValue {
19 fn from(value: ConstBit) -> 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<&ConstSlice> for ParamValue {
37 fn from(value: &ConstSlice) -> Self {
38 Self::Const(value.to_owned())
39 }
40}
41
42impl From<i64> for ParamValue {
43 fn from(value: i64) -> Self {
44 Self::Int(value)
45 }
46}
47
48impl From<String> for ParamValue {
49 fn from(value: String) -> Self {
50 Self::String(value)
51 }
52}
53
54impl From<&str> for ParamValue {
55 fn from(value: &str) -> Self {
56 Self::String(value.into())
57 }
58}
59
60impl Display for ParamValue {
61 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
62 match self {
63 ParamValue::Const(value) => write!(f, "{value}"),
64 ParamValue::Int(value) => write!(f, "#{value}"),
65 ParamValue::Float(_value) => unimplemented!("float parameter"),
66 ParamValue::String(value) => Design::write_string(f, value),
67 }
68 }
69}