mod case;
mod metadata;
mod positions;
mod schema;
mod structs;
pub use case::*;
pub use metadata::*;
pub use positions::*;
pub use schema::*;
pub use structs::*;
#[derive(Clone, Copy)]
pub struct GenericSyntax {
pub open: char,
pub close: char,
pub default_type: &'static str,
}
impl GenericSyntax {
pub const PYTHON: Self = Self {
open: '[',
close: ']',
default_type: "Any",
};
pub const JAVASCRIPT: Self = Self {
open: '<',
close: '>',
default_type: "unknown",
};
pub const RUST: Self = Self {
open: '<',
close: '>',
default_type: "_",
};
pub fn wrap(&self, name: &str, type_param: &str) -> String {
let converted = self.convert(type_param);
format!("{}{}{}{}", name, self.open, converted, self.close)
}
pub fn convert(&self, type_str: &str) -> String {
extract_inner_type_recursive(type_str)
}
}
fn extract_inner_type_recursive(type_str: &str) -> String {
if let Some(start) = type_str.find('<')
&& let Some(end) = type_str.rfind('>')
{
let inner = &type_str[start + 1..end];
return extract_inner_type_recursive(inner);
}
type_str.to_string()
}