Skip to main content

oxilean_codegen/wasm_component_backend/
wasmcomponentexpr_traits.rs

1//! # WasmComponentExpr - Trait Implementations
2//!
3//! This module contains trait implementations for `WasmComponentExpr`.
4//!
5//! ## Implemented Traits
6//!
7//! - `Display`
8//!
9//! 🤖 Generated with [SplitRS](https://github.com/cool-japan/splitrs)
10
11use super::types::WasmComponentExpr;
12use std::fmt;
13
14impl fmt::Display for WasmComponentExpr {
15    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
16        match self {
17            WasmComponentExpr::Lift {
18                func, result_type, ..
19            } => {
20                write!(f, "(lift {} {})", func, result_type)
21            }
22            WasmComponentExpr::Lower { func, .. } => write!(f, "(lower {})", func),
23            WasmComponentExpr::ResourceNew {
24                resource,
25                core_func,
26            } => {
27                write!(f, "(resource.new {} {})", resource, core_func)
28            }
29            WasmComponentExpr::ResourceDrop { resource } => {
30                write!(f, "(resource.drop {})", resource)
31            }
32            WasmComponentExpr::ResourceRep { resource } => {
33                write!(f, "(resource.rep {})", resource)
34            }
35            WasmComponentExpr::Call {
36                instance,
37                func,
38                args,
39            } => {
40                write!(f, "({}.{}", instance, func)?;
41                for a in args {
42                    write!(f, " {}", a)?;
43                }
44                write!(f, ")")
45            }
46            WasmComponentExpr::IntLit(n) => write!(f, "{}", n),
47            WasmComponentExpr::FloatLit(n) => write!(f, "{}", n),
48            WasmComponentExpr::StringLit(s) => write!(f, "\"{}\"", s),
49            WasmComponentExpr::BoolLit(b) => write!(f, "{}", b),
50            WasmComponentExpr::Var(name) => write!(f, "{}", name),
51            WasmComponentExpr::RecordNew(fields) => {
52                write!(f, "{{record")?;
53                for (name, val) in fields {
54                    write!(f, " {}: {}", name, val)?;
55                }
56                write!(f, "}}")
57            }
58            WasmComponentExpr::FieldGet(rec, field) => write!(f, "{}.{}", rec, field),
59            WasmComponentExpr::VariantNew(tag, payload) => match payload.as_ref() {
60                Some(p) => write!(f, "(variant {} {})", tag, p),
61                None => write!(f, "(variant {})", tag),
62            },
63            WasmComponentExpr::OptionSome(v) => write!(f, "(some {})", v),
64            WasmComponentExpr::OptionNone => write!(f, "none"),
65            WasmComponentExpr::ResultOk(v) => match v.as_ref() {
66                Some(inner) => write!(f, "(ok {})", inner),
67                None => write!(f, "ok"),
68            },
69            WasmComponentExpr::ResultErr(v) => match v.as_ref() {
70                Some(inner) => write!(f, "(err {})", inner),
71                None => write!(f, "err"),
72            },
73            WasmComponentExpr::ListNew(items) => {
74                write!(f, "[list")?;
75                for item in items {
76                    write!(f, " {}", item)?;
77                }
78                write!(f, "]")
79            }
80            WasmComponentExpr::TupleNew(elems) => {
81                write!(f, "(tuple")?;
82                for e in elems {
83                    write!(f, " {}", e)?;
84                }
85                write!(f, ")")
86            }
87        }
88    }
89}