pyo3_stub_gen/generate/
member.rs

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