diff --git a/Cargo.toml b/Cargo.toml index 2db2a73..32b8650 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ome-metadata" -version = "0.3.0" +version = "0.3.1" edition = "2024" rust-version = "1.85.1" authors = ["Wim Pomp "] diff --git a/src/lib.rs b/src/lib.rs index 0a1fe87..cfaa233 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,7 @@ #![allow(non_camel_case_types)] pub mod ome; -mod error; +pub mod error; #[cfg(feature = "python")] mod py; diff --git a/src/py.rs b/src/py.rs index 1021419..ac443ad 100644 --- a/src/py.rs +++ b/src/py.rs @@ -6,6 +6,14 @@ use crate::ome::{ use pyo3::exceptions::PyValueError; use pyo3::prelude::*; + +impl From for PyErr { + fn from(err: crate::error::Error) -> PyErr { + PyErr::new::(err.to_string()) + } +} + + macro_rules! impl_enum_into_py_object { ($($s:ident: $t:ty $(,)?)*) => { $( @@ -27,7 +35,7 @@ macro_rules! impl_enum_into_py_object { /// convert a value between units fn convert(&self, unit: &str, value: f64) -> PyResult { match unit.parse() { - Ok(unit) => Ok(self.inner.convert(&unit, value).map_err(|e| PyErr::new::(format!("{}", e)))?), + Ok(unit) => Ok(self.inner.convert(&unit, value)?), Err(_) => Err(PyErr::new::(format!("Invalid unit: {}", unit))) } } @@ -86,8 +94,7 @@ fn ome_metadata_rs(m: &Bound<'_, PyModule>) -> PyResult<()> { #[pyfn(m)] fn ome(text: &str) -> PyResult { - text.parse() - .map_err(|e| PyErr::new::(format!("{}", e))) + Ok(text.parse()?) } Ok(())