Skip to main content

oxilean_codegen/opt_ctfe/
ctfevalueext_traits.rs

1//! # CtfeValueExt - Trait Implementations
2//!
3//! This module contains trait implementations for `CtfeValueExt`.
4//!
5//! ## Implemented Traits
6//!
7//! - `Display`
8//!
9//! 🤖 Generated with [SplitRS](https://github.com/cool-japan/splitrs)
10
11use super::types::CtfeValueExt;
12use std::fmt;
13
14impl std::fmt::Display for CtfeValueExt {
15    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
16        match self {
17            CtfeValueExt::Unit => write!(f, "()"),
18            CtfeValueExt::Bool(b) => write!(f, "{}", b),
19            CtfeValueExt::Int(n) => write!(f, "{}", n),
20            CtfeValueExt::Uint(n) => write!(f, "{}u", n),
21            CtfeValueExt::Float(v) => write!(f, "{}", v),
22            CtfeValueExt::Str(s) => write!(f, "\"{}\"", s),
23            CtfeValueExt::Tuple(vs) => {
24                let ss: Vec<String> = vs.iter().map(|v| v.to_string()).collect();
25                write!(f, "({})", ss.join(", "))
26            }
27            CtfeValueExt::List(vs) => {
28                let ss: Vec<String> = vs.iter().map(|v| v.to_string()).collect();
29                write!(f, "[{}]", ss.join(", "))
30            }
31            CtfeValueExt::Constructor(n, vs) => {
32                if vs.is_empty() {
33                    write!(f, "{}", n)
34                } else {
35                    let ss: Vec<String> = vs.iter().map(|v| v.to_string()).collect();
36                    write!(f, "{} ({})", n, ss.join(", "))
37                }
38            }
39            CtfeValueExt::Closure { params, .. } => {
40                write!(f, "<closure({})>", params.join(", "))
41            }
42            CtfeValueExt::Opaque => write!(f, "<opaque>"),
43        }
44    }
45}