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}
95
96#[derive(Debug)]
98pub struct PyMethodsInfo {
99 pub struct_id: fn() -> TypeId,
101 pub getters: &'static [MemberInfo],
103 pub methods: &'static [MethodInfo],
105}
106
107inventory::collect!(PyMethodsInfo);
108
109#[derive(Debug)]
111pub struct PyClassInfo {
112 pub struct_id: fn() -> TypeId,
114 pub pyclass_name: &'static str,
116 pub module: Option<&'static str>,
118 pub doc: &'static str,
120 pub members: &'static [MemberInfo],
122 pub bases: &'static [fn() -> TypeInfo],
124}
125
126inventory::collect!(PyClassInfo);
127
128#[derive(Debug)]
130pub struct PyEnumInfo {
131 pub enum_id: fn() -> TypeId,
133 pub pyclass_name: &'static str,
135 pub module: Option<&'static str>,
137 pub doc: &'static str,
139 pub variants: &'static [(&'static str, &'static str)],
141}
142
143inventory::collect!(PyEnumInfo);
144
145#[derive(Debug)]
147pub struct PyFunctionInfo {
148 pub name: &'static str,
149 pub args: &'static [ArgInfo],
150 pub r#return: fn() -> TypeInfo,
151 pub doc: &'static str,
152 pub module: Option<&'static str>,
153}
154
155inventory::collect!(PyFunctionInfo);
156
157#[derive(Debug)]
158pub struct PyErrorInfo {
159 pub name: &'static str,
160 pub module: &'static str,
161 pub base: fn() -> &'static str,
162}
163
164inventory::collect!(PyErrorInfo);
165
166#[derive(Debug)]
167pub struct PyVariableInfo {
168 pub name: &'static str,
169 pub module: &'static str,
170 pub r#type: fn() -> TypeInfo,
171}
172
173inventory::collect!(PyVariableInfo);