use crate::Type;
use itertools::Itertools as _;
use serde::{Deserialize, Serialize};
use std::fmt;
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct TupleType {
pub elements: Vec<Type>,
}
impl TupleType {
pub fn new(elements: Vec<Type>) -> Self {
Self { elements }
}
pub fn elements(&self) -> &[Type] {
&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 Type {
fn from(value: TupleType) -> Self {
Type::Tuple(value)
}
}