pyo3/impl_/pyclass/
probes.rs1use std::marker::PhantomData;
2
3use crate::{conversion::IntoPyObject, FromPyObject, Py};
4
5pub trait Probe {
15 const VALUE: bool = false;
16}
17
18macro_rules! probe {
19 ($name:ident) => {
20 pub struct $name<T>(PhantomData<T>);
21 impl<T> Probe for $name<T> {}
22 };
23}
24
25probe!(IsPyT);
26
27impl<T> IsPyT<Py<T>> {
28 pub const VALUE: bool = true;
29}
30
31probe!(IsIntoPyObjectRef);
32
33impl<'a, 'py, T: 'a> IsIntoPyObjectRef<T>
34where
35 &'a T: IntoPyObject<'py>,
36{
37 pub const VALUE: bool = true;
38}
39
40probe!(IsIntoPyObject);
41
42impl<'py, T> IsIntoPyObject<T>
43where
44 T: IntoPyObject<'py>,
45{
46 pub const VALUE: bool = true;
47}
48
49probe!(IsSend);
50
51impl<T: Send> IsSend<T> {
52 pub const VALUE: bool = true;
53}
54
55probe!(IsSync);
56
57impl<T: Sync> IsSync<T> {
58 pub const VALUE: bool = true;
59}
60
61probe!(IsFromPyObject);
62
63impl<'a, 'py, T> IsFromPyObject<T>
64where
65 T: FromPyObject<'a, 'py>,
66{
67 pub const VALUE: bool = true;
68}
69
70probe!(HasNewTextSignature);
71
72impl<T: super::doc::PyClassNewTextSignature> HasNewTextSignature<T> {
73 pub const VALUE: bool = true;
74}
75
76probe!(IsClone);
77
78impl<T: Clone> IsClone<T> {
79 pub const VALUE: bool = true;
80}
81
82probe!(IsReturningEmptyTuple);
83
84impl IsReturningEmptyTuple<()> {
85 pub const VALUE: bool = true;
86}
87
88impl<E> IsReturningEmptyTuple<Result<(), E>> {
89 pub const VALUE: bool = true;
90}
91
92#[cfg(test)]
93macro_rules! value_of {
94 ($probe:ident, $ty:ty) => {{
95 #[allow(unused_imports)] use crate::impl_::pyclass::Probe as _;
97 $probe::<$ty>::VALUE
98 }};
99}
100
101#[cfg(test)]
102pub(crate) use value_of;