use crate::TypeKind;
use itertools::Itertools as _;
use serde::Serialize;
use std::fmt;
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize)]
pub struct TupleType {
pub elements: Vec<TypeKind>,
}
impl TupleType {
pub fn new(elements: Vec<TypeKind>) -> Self {
Self { elements }
}
pub fn elements(&self) -> &[TypeKind] {
&self.elements
}
pub fn length(&self) -> usize {
self.elements.len()
}
}
impl fmt::Display for TupleType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "({})", self.elements.iter().format(", "))
}
}
impl From<TupleType> for TypeKind {
fn from(value: TupleType) -> Self {
TypeKind::Tuple(value)
}
}