pyo3_stub_gen/
type_info.rs1use crate::{PyStubType, TypeInfo};
25use std::any::TypeId;
26
27pub fn compare_op_type_input() -> TypeInfo {
30 <isize as PyStubType>::type_input()
31}
32
33pub fn no_return_type_output() -> TypeInfo {
34 TypeInfo::none()
35}
36
37#[derive(Debug)]
39pub struct ArgInfo {
40 pub name: &'static str,
41 pub r#type: fn() -> TypeInfo,
42 pub signature: Option<SignatureArg>,
43}
44#[derive(Debug, Clone)]
45pub enum SignatureArg {
46 Ident,
47 Assign {
48 default: &'static std::sync::LazyLock<String>,
49 },
50 Star,
51 Args,
52 Keywords,
53}
54
55impl PartialEq for SignatureArg {
56 #[inline]
57 fn eq(&self, other: &Self) -> bool {
58 match (self, other) {
59 (Self::Assign { default: l_default }, Self::Assign { default: r_default }) => {
60 let l_default: &String = l_default;
61 let r_default: &String = r_default;
62 l_default.eq(r_default)
63 }
64 _ => core::mem::discriminant(self) == core::mem::discriminant(other),
65 }
66 }
67}
68
69#[derive(Debug, Clone, Copy, PartialEq)]
71pub enum MethodType {
72 Instance,
73 Static,
74 Class,
75 New,
76}
77
78#[derive(Debug)]
80pub struct MethodInfo {
81 pub name: &'static str,
82 pub args: &'static [ArgInfo],
83 pub r#return: fn() -> TypeInfo,
84 pub doc: &'static str,
85 pub r#type: MethodType,
86}
87
88#[derive(Debug)]
90pub struct MemberInfo {
91 pub name: &'static str,
92 pub r#type: fn() -> TypeInfo,
93 pub doc: &'static str,
94 pub default: Option<&'static std::sync::LazyLock<String>>,
95}
96
97#[derive(Debug)]
99pub struct PyMethodsInfo {
100 pub struct_id: fn() -> TypeId,
102 pub attrs: &'static [MemberInfo],
104 pub getters: &'static [MemberInfo],
106 pub setters: &'static [MemberInfo],
108 pub methods: &'static [MethodInfo],
110}
111
112inventory::collect!(PyMethodsInfo);
113
114#[derive(Debug)]
116pub struct PyClassInfo {
117 pub struct_id: fn() -> TypeId,
119 pub pyclass_name: &'static str,
121 pub module: Option<&'static str>,
123 pub doc: &'static str,
125 pub getters: &'static [MemberInfo],
127 pub setters: &'static [MemberInfo],
129 pub bases: &'static [fn() -> TypeInfo],
131}
132
133inventory::collect!(PyClassInfo);
134
135#[derive(Debug)]
137pub struct PyEnumInfo {
138 pub enum_id: fn() -> TypeId,
140 pub pyclass_name: &'static str,
142 pub module: Option<&'static str>,
144 pub doc: &'static str,
146 pub variants: &'static [(&'static str, &'static str)],
148}
149
150inventory::collect!(PyEnumInfo);
151
152#[derive(Debug)]
154pub struct PyFunctionInfo {
155 pub name: &'static str,
156 pub args: &'static [ArgInfo],
157 pub r#return: fn() -> TypeInfo,
158 pub doc: &'static str,
159 pub module: Option<&'static str>,
160}
161
162inventory::collect!(PyFunctionInfo);
163
164#[derive(Debug)]
165pub struct PyErrorInfo {
166 pub name: &'static str,
167 pub module: &'static str,
168 pub base: fn() -> &'static str,
169}
170
171inventory::collect!(PyErrorInfo);
172
173#[derive(Debug)]
174pub struct PyVariableInfo {
175 pub name: &'static str,
176 pub module: &'static str,
177 pub r#type: fn() -> TypeInfo,
178}
179
180inventory::collect!(PyVariableInfo);