use crate::rust;
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Type {
Bool,
Double,
}
impl core::str::FromStr for Type {
type Err = ();
fn from_str(input: &str) -> Result<Self, Self::Err> {
use Type::*;
Ok(match input {
"bool" => Bool,
"double" => Double,
_ => return Err(()),
})
}
}
impl core::fmt::Display for Type {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
use Type::*;
match self {
Bool => write!(f, "bool"),
Double => write!(f, "double"),
}
}
}
impl TryFrom<rust::Type> for Type {
type Error = ();
fn try_from(input: rust::Type) -> Result<Self, Self::Error> {
use Type::*;
Ok(match input {
rust::Type::Bool => Bool,
rust::Type::F32 | rust::Type::F64 => Double,
_ => return Err(()),
})
}
}
impl crate::ToRust for Type {
fn to_rust(&self) -> Option<rust::Type> {
use Type::*;
Some(match self {
Bool => rust::Type::Bool,
Double => rust::Type::F64,
})
}
}
impl crate::Type for Type {}