use super::RTypeTrait;
mod enumtype;
pub use enumtype::EnumType;
#[derive(Debug, Eq, PartialEq)]
pub enum SpecialType {
Enum(String), Regex,
Bool,
}
impl SpecialType {
}
impl RTypeTrait for SpecialType {
#[allow(unused_variables)]
fn from_typestr<T: AsRef<str>>(typestr: T) -> Result<Self, super::TypeError> where Self: Sized {
use super::TypeError;
Err(TypeError::SPECIALTYPEPARSE)
}
fn to_typestr(&self) -> String {
match self {
Self::Enum(x) => {x.to_owned()},
Self::Bool => {"bool".to_string()},
Self::Regex => {"Regex".to_string()},
}
}
fn to_typestr_no_ref(&self) -> String {
self.to_typestr()
}
fn to_typestr_no_life(&self) -> String {
self.to_typestr()
}
#[allow(unused_variables)]
fn collect_lifetimes(&self, into: &mut Vec<String>) {
}
fn is_const(&self) -> bool {
match self {
Self::Bool => {true},
Self::Regex => {true}, _ => {false},
}
}
fn value_is_valid(&self, valuestr: &str) -> bool {
match self {
Self::Enum(x) => {EnumType::value_is_valid_enum(x, valuestr)},
Self::Regex => {
true},
Self::Bool => {
let valstr = valuestr.trim();
match valstr {
"true" | "True" | "1" | "false" | "False" | "0" => {true}
_ => false
}
},
}
}
fn get_depth(&self, counter: usize) -> usize {
match self {
Self::Regex => {counter + 2},
_ => {counter + 0}
}
}
fn get_breadth(&self, counter: usize) -> usize {
match self {
Self::Regex => {counter + 5},
_ => {counter + 0}
}
}
fn wrap_valuestr(&self, valuestr: &str) -> String {
match self {
Self::Enum(x) => {
if !valuestr.contains(x) {
format!("{}::{}",x , valuestr)
} else {valuestr.to_string()}
},
Self::Regex => {
format!("r\"{}\"", valuestr)
},
Self::Bool => {
let valstr = valuestr.trim();
match valstr {
"true" | "True" | "1" => "true".to_string(),
"false" | "False" | "0" => "false".to_string(),
_ => "false".to_string()
}
},
}
}
fn can_match_as_key(&self) -> bool {
true
}
}