ligen_ir/types/
generics.rs1use crate::Type;
2use crate::prelude::*;
3
4#[derive(Default, Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
6pub struct Generics {
7 pub types: Vec<Type>
9}
10
11impl<T: Into<Type>> From<Vec<T>> for Generics {
12 fn from(value: Vec<T>) -> Self {
13 let types = value
14 .into_iter()
15 .map(|type_| type_.into())
16 .collect();
17 Self { types }
18 }
19}
20
21impl From<Type> for Generics {
22 fn from(value: Type) -> Self {
23 let types = vec![value];
24 Self { types }
25 }
26}
27
28impl std::fmt::Display for Generics {
29 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
30 if self.types.is_empty() {
31 f.write_str("")
32 } else {
33 let generics = self
34 .types
35 .iter()
36 .map(|generic| format!("{}", generic))
37 .collect::<Vec<String>>()
38 .join(", ");
39 f.write_str(&format!("<{}>", generics))
40 }
41 }
42}
43
44