pyo3_stub_gen/generate/
variable.rs1use std::fmt;
2
3use crate::{type_info::PyVariableInfo, TypeInfo};
4
5#[derive(Debug, Clone, PartialEq)]
6pub struct VariableDef {
7 pub name: &'static str,
8 pub type_: TypeInfo,
9 pub default: Option<String>,
10}
11
12impl From<&PyVariableInfo> for VariableDef {
13 fn from(info: &PyVariableInfo) -> Self {
14 Self {
15 name: info.name,
16 type_: (info.r#type)(),
17 default: info.default.map(|f| f()),
18 }
19 }
20}
21
22impl fmt::Display for VariableDef {
23 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
24 write!(f, "{}: {}", self.name, self.type_)?;
25 if let Some(default) = &self.default {
26 write!(f, " = {default}")?;
27 }
28 Ok(())
29 }
30}