Skip to main content

oxilean_codegen/matlab_backend/
matlabliteral_traits.rs

1//! # MatlabLiteral - Trait Implementations
2//!
3//! This module contains trait implementations for `MatlabLiteral`.
4//!
5//! ## Implemented Traits
6//!
7//! - `Display`
8//!
9//! 🤖 Generated with [SplitRS](https://github.com/cool-japan/splitrs)
10
11use super::types::MatlabLiteral;
12use std::fmt;
13
14impl std::fmt::Display for MatlabLiteral {
15    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
16        match self {
17            MatlabLiteral::Double(v) => {
18                if v.fract() == 0.0 && v.abs() < 1e15 {
19                    write!(f, "{}", *v as i64)
20                } else {
21                    write!(f, "{}", v)
22                }
23            }
24            MatlabLiteral::Integer(n) => write!(f, "{}", n),
25            MatlabLiteral::Logical(b) => {
26                write!(f, "{}", if *b { "true" } else { "false" })
27            }
28            MatlabLiteral::Char(s) => write!(f, "'{}'", s.replace('\'', "''")),
29            MatlabLiteral::Str(s) => write!(f, "\"{}\"", s.replace('"', "\"\"")),
30            MatlabLiteral::Empty => write!(f, "[]"),
31            MatlabLiteral::NaN => write!(f, "NaN"),
32            MatlabLiteral::Inf(neg) => write!(f, "{}Inf", if *neg { "-" } else { "" }),
33            MatlabLiteral::Pi => write!(f, "pi"),
34            MatlabLiteral::Eps => write!(f, "eps"),
35        }
36    }
37}