gesha_rust_types/
data_type.rs

1use std::fmt::{Debug, Display, Formatter};
2
3#[derive(Clone, Debug, Hash, Eq, PartialEq)]
4pub enum DataType {
5    Bool,
6    Int32,
7    Int64,
8    Float32,
9    Float64,
10    Option(Box<DataType>),
11    Patch(Box<DataType>),
12    String,
13    Vec(Box<DataType>),
14    Custom(String),
15}
16
17impl Display for DataType {
18    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
19        let x = String::from(self.clone());
20        Display::fmt(&x, f)
21    }
22}
23
24impl From<DataType> for String {
25    fn from(x: DataType) -> Self {
26        match x {
27            DataType::Bool => "bool".to_string(),
28            DataType::Int32 => "i32".to_string(),
29            DataType::Int64 => "i64".to_string(),
30            DataType::Float32 => "f32".to_string(),
31            DataType::Float64 => "f64".to_string(),
32            DataType::Option(x) => format!("Option<{}>", String::from(*x)),
33            DataType::Patch(x) => format!("Patch<{}>", String::from(*x)),
34            DataType::String => "String".to_string(),
35            DataType::Vec(x) => format!("Vec<{}>", String::from(*x)),
36            DataType::Custom(x) => x,
37        }
38    }
39}