Skip to content

Commit ba898bd

Browse files
apcamargoaudy
authored andcommitted
Add a __next__ method to PyFastxReader
1 parent f19eba7 commit ba898bd

File tree

1 file changed

+12
-21
lines changed

1 file changed

+12
-21
lines changed

src/python.rs

+12-21
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,20 @@ pub struct PyFastxReader {
2828
#[pymethods]
2929
impl PyFastxReader {
3030
fn __repr__(&self) -> PyResult<String> {
31-
Ok("<FastxParser>".to_string())
31+
Ok("<FastxReader>".to_string())
3232
}
3333

34-
fn __iter__(slf: PyRefMut<Self>, py: Python<'_>) -> PyResult<FastxReaderIterator> {
35-
Ok(FastxReaderIterator { t: slf.into_py(py) })
34+
fn __iter__(slf: PyRefMut<Self>) -> PyRefMut<Self> {
35+
slf
36+
}
37+
38+
fn __next__(mut slf: PyRefMut<Self>) -> PyResult<Option<Record>> {
39+
if let Some(rec) = slf.reader.next() {
40+
let record = py_try!(rec);
41+
Ok(Some(Record::from_sequence_record(&record)))
42+
} else {
43+
Ok(None)
44+
}
3645
}
3746
}
3847

@@ -74,24 +83,6 @@ impl Record {
7483
}
7584
}
7685

77-
#[pyclass]
78-
pub struct FastxReaderIterator {
79-
t: PyObject,
80-
}
81-
82-
#[pymethods]
83-
impl FastxReaderIterator {
84-
fn __next__(slf: PyRef<Self>, py: Python<'_>) -> PyResult<Option<Record>> {
85-
let mut parser: PyRefMut<PyFastxReader> = slf.t.extract(py)?;
86-
if let Some(rec) = parser.reader.next() {
87-
let record = py_try!(rec);
88-
Ok(Some(Record::from_sequence_record(&record)))
89-
} else {
90-
Ok(None)
91-
}
92-
}
93-
}
94-
9586
// TODO: what would be really nice is to detect the type of pyobject so it would on file object etc
9687
// not for initial release though
9788

0 commit comments

Comments
 (0)