Skip to content

Commit

Permalink
Slight simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhewitt committed Jan 14, 2020
1 parent 2324297 commit 541d875
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::object::PyObject;
use crate::type_object::{PyObjectLayout, PyTypeInfo};
use crate::types::PyAny;
use crate::types::PyTuple;
use crate::{ffi, gil, Py, PyNativeType, Python};
use crate::{ffi, gil, Py, Python};
use std::ptr::NonNull;

/// This trait represents that, **we can do zero-cost conversion from the object to FFI pointer**.
Expand Down Expand Up @@ -248,7 +248,7 @@ pub mod extract_impl {
use super::*;

pub trait ExtractImpl<'a, Target>: Sized {
fn extract(source: &'a PyAny, py: Python<'a>) -> PyResult<Target>;
fn extract(source: &'a PyAny) -> PyResult<Target>;
}

pub struct Cloned;
Expand All @@ -260,16 +260,16 @@ pub mod extract_impl {
T: Clone,
Reference: ExtractImpl<'a, &'a T>,
{
fn extract(source: &'a PyAny, py: Python<'a>) -> PyResult<T> {
Ok(Reference::extract(source, py)?.clone())
fn extract(source: &'a PyAny) -> PyResult<T> {
Ok(Reference::extract(source)?.clone())
}
}

impl<'a, T> ExtractImpl<'a, &'a T> for Reference
where
T: PyTryFrom<'a>,
{
fn extract(source: &'a PyAny, _: Python<'a>) -> PyResult<&'a T> {
fn extract(source: &'a PyAny) -> PyResult<&'a T> {
Ok(T::try_from(source)?)
}
}
Expand All @@ -278,7 +278,7 @@ pub mod extract_impl {
where
T: PyTryFrom<'a>,
{
fn extract(source: &'a PyAny, _: Python<'a>) -> PyResult<&'a mut T> {
fn extract(source: &'a PyAny) -> PyResult<&'a mut T> {
Ok(T::try_from_mut(source)?)
}
}
Expand All @@ -297,12 +297,12 @@ use extract_impl::ExtractImpl;
///
/// Most users should implement `FromPyObject` directly instead of via this trait..
pub trait FromPyObjectImpl {
// We deliberately don't require Policy: ExtractImpl here because we allow #[pyclass]
// to specify Policies when they don't satisfy the ExtractImpl constraints.
// We deliberately don't require Impl: ExtractImpl here because we allow #[pyclass]
// to specify an Impl which doesn't satisfy the ExtractImpl constraints.
//
// e.g. non-clone #[pyclass] can still have Policy: Cloned.
// e.g. non-clone #[pyclass] can still have Impl: Cloned.
//
// We catch invalid policies in the blanket impl for FromPyObject, which only
// We catch invalid Impls in the blanket impl for FromPyObject, which only
// complains when .extract() is actually used.
type Impl;
}
Expand All @@ -314,7 +314,7 @@ where
{
#[inline]
fn extract(ob: &'a PyAny) -> PyResult<T> {
<T as FromPyObjectImpl>::Impl::extract(ob, ob.py())
<T as FromPyObjectImpl>::Impl::extract(ob)
}
}

Expand Down

0 comments on commit 541d875

Please sign in to comment.