1use crate::{generate::*, type_info::*, TypeInfo};
2use std::{collections::HashSet, fmt};
3
4/// Definition of a class member.
5#[derive(Debug, Clone, PartialEq)]
6pub struct MemberDef {
7 pub name: &'static str,
8 pub r#type: TypeInfo,
9}
10
11impl Import for MemberDef {
12 fn import(&self) -> HashSet<ModuleRef> {
13 self.r#type.import.clone()
14 }
15}
16
17impl From<&MemberInfo> for MemberDef {
18 fn from(info: &MemberInfo) -> Self {
19 Self {
20 name: info.name,
21 r#type: (info.r#type)(),
22 }
23 }
24}
25
26impl fmt::Display for MemberDef {
27 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
28 let indent: &'static str = indent();
29 writeln!(f, "{indent}{}: {}", self.name, self.r#type)
30 }
31}
32