1use std::fmt::Display;
2
3use crate::Type;
4
5#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
6#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
7#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))]
8pub struct Tuple {
9 pub(crate) types: Vec<Type>,
10}
11
12impl Tuple {
13 pub fn empty() -> Self {
14 Default::default()
15 }
16
17 pub fn type_(&mut self, type_: impl Into<Type>) {
18 self.types.push(type_.into());
19 }
20
21 pub fn types(&self) -> &[Type] {
22 &self.types
23 }
24
25 pub fn types_mut(&mut self) -> &mut Vec<Type> {
26 &mut self.types
27 }
28}
29
30impl Display for Tuple {
31 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
32 write!(f, "tuple<")?;
33 let mut peekable = self.types.iter().peekable();
34 while let Some(type_) = peekable.next() {
35 type_.fmt(f)?;
36 if peekable.peek().is_some() {
37 write!(f, ", ")?;
38 }
39 }
40 write!(f, ">")?;
41 Ok(())
42 }
43}