microcad_lang/lower/ir/format_string/
format_expression.rs1use crate::lower::ir;
7
8use microcad_lang_base::SrcRef;
9use microcad_lang_proc_macros::SrcReferrer;
10
11#[derive(Clone, Debug, SrcReferrer)]
13pub struct FormatExpression {
14 pub spec: Option<ir::FormatSpec>,
16 pub expression: ir::Expression,
18 src_ref: SrcRef,
20}
21
22impl FormatExpression {
23 pub fn new(spec: Option<ir::FormatSpec>, expression: ir::Expression, src_ref: SrcRef) -> Self {
25 Self {
26 src_ref,
27 spec,
28 expression,
29 }
30 }
31}
32
33impl std::fmt::Display for FormatExpression {
34 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
35 if let Some(spec) = &self.spec {
36 write!(f, "{{{}:{}}}", spec, self.expression)
37 } else {
38 write!(f, "{{{}}}", self.expression)
39 }
40 }
41}