#[derive(Debug, Default, Clone)] pub struct Type { pub subtypes: Vec>, pub repr: String, } impl Type { /// A function to print a Type struct as a python String /// /// # Examples /// /// Creating a simple type and converting it into a python type String /// ``` /// # use parsing::nested_type::Type; /// let my_type = Type{repr: "Type".into(), ..Default::default()}; /// my_type.to_python(); /// ``` pub fn to_python(&self) -> String { match self.subtypes.len() { 0 => format!("{}", self.repr), _ => format!( "{}[{}]", self.repr, self.subtypes .iter() .map(|s| s.to_python()) .collect::>() .join(", ") ), } } pub fn to_cpp(&self) -> String { match self.subtypes.len() { 0 => format!("{}", self.repr), _ => format!( "{}<{}>", self.repr, self.subtypes .iter() .map(|s| s.to_python()) .collect::>() .join(", ") ), } } }