-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow fasta_digest to accept Path or bytes #93
Comments
PyO3 has a lot of native mappings from Python types to Rust types. If you want to accept that said... I wonder if we could leverage the Something like: #[pyfunction]
pub fn digest_fasta(fasta: PyObject) -> PyResult<Vec<PyDigestResult>> {
let fasta_file;
if let Ok(fasta) = fasta.extract::<PyString>() {
fasta_file = fasta;
} else if let Ok(fasta) = fasta.extract::<PathBuf>() {
fasta_file = fasta;
} else {
return Err(PyErr::new::<pyo3::exceptions::PyIOError, _>(format!("Must be of type String or Path"))
}
match gtars::digests::digest_fasta(fasta) {
Ok(digest_results) => {
let py_digest_results: Vec<PyDigestResult> = digest_results.into_iter().map(PyDigestResult::from).collect();
Ok(py_digest_results)
},
Err(e) => Err(PyErr::new::<pyo3::exceptions::PyIOError, _>(format!("Error processing FASTA file: {}", e))),
}
} |
I went a different direction in the end. The Instead I can use |
Right now digest_fasta strictly requires a string.
works:
Doesn't work:
Also fails:
Would it be easy/possible/advisable to make this friendly enough to convert string-like inputs to string automatically?
Raised by @stolarczyk
The text was updated successfully, but these errors were encountered: