Leverage simplified Python protocols
This commit is contained in:
parent
b0c7dab6e5
commit
c302360587
|
@ -7,11 +7,9 @@ use std::iter::FromIterator;
|
||||||
use instant_distance::Point;
|
use instant_distance::Point;
|
||||||
use pyo3::conversion::IntoPy;
|
use pyo3::conversion::IntoPy;
|
||||||
use pyo3::exceptions::{PyTypeError, PyValueError};
|
use pyo3::exceptions::{PyTypeError, PyValueError};
|
||||||
use pyo3::proc_macro::{pyclass, pymethods, pymodule, pyproto};
|
use pyo3::proc_macro::{pyclass, pymethods, pymodule};
|
||||||
use pyo3::types::{PyList, PyModule, PyString};
|
use pyo3::types::{PyList, PyModule, PyString};
|
||||||
use pyo3::{
|
use pyo3::{Py, PyAny, PyErr, PyObject, PyRef, PyRefMut, PyResult, Python};
|
||||||
Py, PyAny, PyErr, PyIterProtocol, PyObject, PyObjectProtocol, PyRef, PyRefMut, PyResult, Python,
|
|
||||||
};
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_big_array::big_array;
|
use serde_big_array::big_array;
|
||||||
|
|
||||||
|
@ -158,10 +156,7 @@ impl Search {
|
||||||
cur: None,
|
cur: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#[pyproto]
|
|
||||||
impl PyIterProtocol for Search {
|
|
||||||
fn __iter__(slf: PyRef<Self>) -> PyRef<Self> {
|
fn __iter__(slf: PyRef<Self>) -> PyRef<Self> {
|
||||||
slf
|
slf
|
||||||
}
|
}
|
||||||
|
@ -330,8 +325,8 @@ struct Neighbor {
|
||||||
value: PyObject,
|
value: PyObject,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[pyproto]
|
#[pymethods]
|
||||||
impl PyObjectProtocol for Neighbor {
|
impl Neighbor {
|
||||||
fn __repr__(&self) -> PyResult<String> {
|
fn __repr__(&self) -> PyResult<String> {
|
||||||
match Python::with_gil(|py| self.value.is_none(py)) {
|
match Python::with_gil(|py| self.value.is_none(py)) {
|
||||||
false => Ok(format!(
|
false => Ok(format!(
|
||||||
|
|
Loading…
Reference in New Issue