diff --git a/src/handlers.rs b/src/handlers.rs index e07c156a..7b8239c0 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -207,6 +207,8 @@ impl Drop for PythonCallback { } } +// the generic type is not useful per se, it just there to make typing +// prettier, e.g. to have `get` returning a `PyResult>` pub(crate) enum HandlerImpl { Rust(Py, PhantomData), Python(PyObject), @@ -239,10 +241,7 @@ impl ToPyObject for HandlerImpl { } } -impl HandlerImpl -where - T::Into: IntoPython, -{ +impl HandlerImpl { pub(crate) fn try_recv(&self, py: Python) -> PyResult { match self { Self::Rust(handler, _) => handler.borrow(py).try_recv(py), @@ -258,11 +257,11 @@ where } } -struct RustHandler +struct RustHandler where - H::Into: IntoHandler, + H::Into: IntoHandler, { - handler: >::Handler, + handler: >::Handler, _phantom: PhantomData, } @@ -300,10 +299,7 @@ impl fmt::Display for DeadlineError { } } -impl Receiver for RustHandler -where - T::Into: IntoPython, -{ +impl Receiver for RustHandler { fn type_name(&self) -> &'static str { short_type_name::() } @@ -325,10 +321,7 @@ where } } -impl Receiver for RustHandler -where - T::Into: IntoPython, -{ +impl Receiver for RustHandler { fn type_name(&self) -> &'static str { short_type_name::() } @@ -350,10 +343,7 @@ where } } -impl Receiver for RustHandler -where - T::Into: IntoPython, -{ +impl Receiver for RustHandler { fn type_name(&self) -> &'static str { short_type_name::() } @@ -375,14 +365,13 @@ where } } -fn rust_handler( +fn rust_handler( py: Python, into_handler: H, -) -> (RustCallback, HandlerImpl) +) -> (RustCallback, HandlerImpl) where - H::Into: IntoHandler, - >::Handler: Send + Sync, - T::Into: IntoPython, + H::Into: IntoHandler, + >::Handler: Send + Sync, RustHandler: Receiver, { let (callback, handler) = into_handler.into_rust().into_handler(); @@ -418,13 +407,10 @@ fn python_callback(callback: &Bound) -> PyResult( +pub(crate) fn into_handler( py: Python, obj: Option<&Bound>, -) -> PyResult<(impl IntoHandler>, bool)> -where - T::Into: IntoPython, -{ +) -> PyResult<(impl IntoHandler>, bool)> { let mut background = false; let Some(obj) = obj else { return Ok((rust_handler(py, DefaultHandler), background)); diff --git a/src/utils.rs b/src/utils.rs index 9b2ddb34..24edd7a5 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -37,14 +37,14 @@ impl IntoPyResult for Result { } } -pub(crate) trait IntoRust: Send + Sync + 'static { +pub(crate) trait IntoRust: 'static { type Into; fn into_rust(self) -> Self::Into; } into_rust!(bool, Duration); -pub(crate) trait IntoPython: Sized + Send + 'static { +pub(crate) trait IntoPython: Sized + Send + Sync + 'static { type Into: IntoPy; fn into_python(self) -> Self::Into; fn into_pyobject(self, py: Python) -> PyObject {