- make error mod public
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "ome-metadata"
|
name = "ome-metadata"
|
||||||
version = "0.3.0"
|
version = "0.3.1"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
rust-version = "1.85.1"
|
rust-version = "1.85.1"
|
||||||
authors = ["Wim Pomp <w.pomp@nki.nl>"]
|
authors = ["Wim Pomp <w.pomp@nki.nl>"]
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#![allow(non_camel_case_types)]
|
#![allow(non_camel_case_types)]
|
||||||
pub mod ome;
|
pub mod ome;
|
||||||
|
|
||||||
mod error;
|
pub mod error;
|
||||||
#[cfg(feature = "python")]
|
#[cfg(feature = "python")]
|
||||||
mod py;
|
mod py;
|
||||||
|
|
||||||
|
|||||||
13
src/py.rs
13
src/py.rs
@@ -6,6 +6,14 @@ use crate::ome::{
|
|||||||
use pyo3::exceptions::PyValueError;
|
use pyo3::exceptions::PyValueError;
|
||||||
use pyo3::prelude::*;
|
use pyo3::prelude::*;
|
||||||
|
|
||||||
|
|
||||||
|
impl From<crate::error::Error> for PyErr {
|
||||||
|
fn from(err: crate::error::Error) -> PyErr {
|
||||||
|
PyErr::new::<PyValueError, _>(err.to_string())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
macro_rules! impl_enum_into_py_object {
|
macro_rules! impl_enum_into_py_object {
|
||||||
($($s:ident: $t:ty $(,)?)*) => {
|
($($s:ident: $t:ty $(,)?)*) => {
|
||||||
$(
|
$(
|
||||||
@@ -27,7 +35,7 @@ macro_rules! impl_enum_into_py_object {
|
|||||||
/// convert a value between units
|
/// convert a value between units
|
||||||
fn convert(&self, unit: &str, value: f64) -> PyResult<f64> {
|
fn convert(&self, unit: &str, value: f64) -> PyResult<f64> {
|
||||||
match unit.parse() {
|
match unit.parse() {
|
||||||
Ok(unit) => Ok(self.inner.convert(&unit, value).map_err(|e| PyErr::new::<PyValueError, _>(format!("{}", e)))?),
|
Ok(unit) => Ok(self.inner.convert(&unit, value)?),
|
||||||
Err(_) => Err(PyErr::new::<PyValueError, _>(format!("Invalid unit: {}", unit)))
|
Err(_) => Err(PyErr::new::<PyValueError, _>(format!("Invalid unit: {}", unit)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -86,8 +94,7 @@ fn ome_metadata_rs(m: &Bound<'_, PyModule>) -> PyResult<()> {
|
|||||||
|
|
||||||
#[pyfn(m)]
|
#[pyfn(m)]
|
||||||
fn ome(text: &str) -> PyResult<Ome> {
|
fn ome(text: &str) -> PyResult<Ome> {
|
||||||
text.parse()
|
Ok(text.parse()?)
|
||||||
.map_err(|e| PyErr::new::<PyValueError, _>(format!("{}", e)))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
Reference in New Issue
Block a user