pr 22
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub enum Type {
|
||||
@@ -13,8 +14,38 @@ pub enum Type {
|
||||
Service(String),
|
||||
Contract(String),
|
||||
ErrorType(String),
|
||||
Array(Box<Type>, u32),
|
||||
Function {
|
||||
params: Vec<Type>,
|
||||
return_type: Box<Type>,
|
||||
},
|
||||
}
|
||||
|
||||
impl fmt::Display for Type {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Type::Void => write!(f, "void"),
|
||||
Type::Int => write!(f, "int"),
|
||||
Type::Float => write!(f, "float"),
|
||||
Type::Bool => write!(f, "bool"),
|
||||
Type::String => write!(f, "string"),
|
||||
Type::Optional(inner) => write!(f, "optional<{}>", inner),
|
||||
Type::Result(ok, err) => write!(f, "result<{}, {}>", ok, err),
|
||||
Type::Struct(name) => write!(f, "{}", name),
|
||||
Type::Service(name) => write!(f, "{}", name),
|
||||
Type::Contract(name) => write!(f, "{}", name),
|
||||
Type::ErrorType(name) => write!(f, "{}", name),
|
||||
Type::Array(inner, size) => write!(f, "array<{}>[{}]", inner, size),
|
||||
Type::Function { params, return_type } => {
|
||||
write!(f, "fn(")?;
|
||||
for (i, param) in params.iter().enumerate() {
|
||||
if i > 0 {
|
||||
write!(f, ", ")?;
|
||||
}
|
||||
write!(f, "{}", param)?;
|
||||
}
|
||||
write!(f, ") -> {}", return_type)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user