use crate::*;
impl FromStr for FuncType {
type Err = String;
#[inline(always)]
fn from_str(s: &str) -> Result<FuncType, String> {
match s {
GET => Ok(FuncType::Get),
GET_MUT => Ok(FuncType::GetMut),
SET => Ok(FuncType::Set),
DEBUG => Ok(FuncType::Debug),
NEW => Ok(FuncType::New),
_ => Ok(FuncType::Unknown),
}
}
}
impl FuncType {
#[inline(always)]
pub(crate) fn is_get(&self) -> bool {
*self == FuncType::Get
}
#[inline(always)]
pub(crate) fn is_get_mut(&self) -> bool {
*self == FuncType::GetMut
}
#[inline(always)]
pub(crate) fn is_set(&self) -> bool {
*self == FuncType::Set
}
#[inline(always)]
pub(crate) fn is_debug(&self) -> bool {
*self == FuncType::Debug
}
#[inline(always)]
pub(crate) fn is_new(&self) -> bool {
*self == FuncType::New
}
#[inline(always)]
pub(crate) fn is_unknown(&self) -> bool {
*self == Self::Unknown
}
#[inline(always)]
pub(crate) fn is_known(func_type_str: &str) -> bool {
let func_type: FuncType = func_type_str.parse::<FuncType>().unwrap_or_default();
func_type != Self::Unknown
}
}
impl FromStr for ReturnType {
type Err = String;
#[inline(always)]
fn from_str(s: &str) -> Result<ReturnType, String> {
match s {
CLONE => Ok(ReturnType::Clone),
COPY => Ok(ReturnType::Copy),
DEREF => Ok(ReturnType::Deref),
_ => Ok(ReturnType::Reference),
}
}
}
impl From<&str> for ParameterType {
#[inline(always)]
fn from(type_str: &str) -> Self {
let trimmed: &str = type_str.trim();
if trimmed.starts_with(AS_REF_PREFIX) && trimmed.ends_with(CLOSE_BRACKET) {
ParameterType::AsRef
} else if trimmed.starts_with(INTO_PREFIX) && trimmed.ends_with(CLOSE_BRACKET) {
ParameterType::Into
} else if trimmed.starts_with(AS_MUT_PREFIX) && trimmed.ends_with(CLOSE_BRACKET) {
ParameterType::AsMut
} else if trimmed.starts_with(DEREF_PREFIX) && trimmed.ends_with(CLOSE_BRACKET) {
ParameterType::Deref
} else if trimmed.contains(OPEN_BRACKET)
&& trimmed.contains(CLOSE_BRACKET)
&& !trimmed.starts_with(IMPL_PREFIX)
{
ParameterType::Custom(trimmed.to_string())
} else {
ParameterType::Direct
}
}
}