use crate::error::{Error, Result};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LigoType {
Int,
UInt,
Real4,
Real8,
Str,
Ilwd,
}
impl LigoType {
pub fn parse(s: &str) -> Result<Self> {
match s {
"int_2s" | "int_4s" | "int_8s" | "int" => Ok(Self::Int),
"int_2u" | "int_4u" | "int_8u" => Ok(Self::UInt),
"real_4" | "float" => Ok(Self::Real4),
"real_8" | "double" => Ok(Self::Real8),
"lstring" | "char_s" | "char_v" | "string" => Ok(Self::Str),
"ilwd:char" => Ok(Self::Ilwd),
other => Err(Error::UnknownType(other.to_string())),
}
}
pub fn canonical_name(self) -> &'static str {
match self {
Self::Int => "int_8s",
Self::UInt => "int_8u",
Self::Real4 => "real_4",
Self::Real8 => "real_8",
Self::Str => "lstring",
Self::Ilwd => "ilwd:char",
}
}
pub fn as_str(self) -> &'static str {
match self {
Self::Int => "int",
Self::UInt => "uint",
Self::Real4 => "real_4",
Self::Real8 => "real_8",
Self::Str => "string",
Self::Ilwd => "ilwd:char",
}
}
pub fn is_quoted(self) -> bool {
matches!(self, Self::Str | Self::Ilwd)
}
}