pyo3_bindgen_engine/typing/
mod.rs

1pub(crate) mod from_py;
2pub(crate) mod into_rs;
3
4/// Enum that maps Python types to Rust types.
5#[derive(Debug, Clone, PartialEq, Eq, Hash)]
6pub enum Type {
7    PyAny,
8    Other(String),
9    Unknown,
10
11    // Primitives
12    PyBool,
13    PyByteArray,
14    PyBytes,
15    PyFloat,
16    PyLong,
17    PyString,
18
19    // Enums
20    Optional(Box<Type>),
21    Union(Vec<Type>),
22    PyNone,
23
24    // Collections
25    PyDict {
26        key_type: Box<Type>,
27        value_type: Box<Type>,
28    },
29    PyFrozenSet(Box<Type>),
30    PyList(Box<Type>),
31    PySet(Box<Type>),
32    PyTuple(Vec<Type>),
33
34    // Additional types - std
35    IpV4Addr,
36    IpV6Addr,
37    Path,
38    PySlice,
39
40    // Additional types - num-complex
41    PyComplex,
42
43    // Additional types - datetime
44    #[cfg(not(Py_LIMITED_API))]
45    PyDate,
46    #[cfg(not(Py_LIMITED_API))]
47    PyDateTime,
48    PyDelta,
49    #[cfg(not(Py_LIMITED_API))]
50    PyTime,
51    #[cfg(not(Py_LIMITED_API))]
52    PyTzInfo,
53
54    // Python-specific types
55    PyCapsule,
56    PyCFunction,
57    #[cfg(not(Py_LIMITED_API))]
58    PyCode,
59    PyEllipsis,
60    #[cfg(all(not(Py_LIMITED_API), not(PyPy)))]
61    PyFrame,
62    PyFunction {
63        param_types: Vec<Type>,
64        return_annotation: Box<Type>,
65    },
66    PyModule,
67    #[cfg(not(PyPy))]
68    PySuper,
69    PyTraceback,
70    #[allow(clippy::enum_variant_names)]
71    PyType,
72}
73
74impl Type {
75    fn is_hashable(&self) -> bool {
76        matches!(
77            self,
78            Self::PyBool
79                | Self::IpV4Addr
80                | Self::IpV6Addr
81                | Self::Path
82                | Self::PyDelta
83                | Self::PyDict { .. }
84                | Self::PyFrozenSet(..)
85                | Self::PyLong
86                | Self::PySet(..)
87                | Self::PyString
88        )
89    }
90}