- use color-eyre

This commit is contained in:
w.pomp
2026-01-23 11:16:10 +01:00
parent 86f1c50c30
commit 8883ae7e5e
4 changed files with 38 additions and 32 deletions
+2 -2
View File
@@ -135,8 +135,8 @@ impl Tag {
}
}
pub fn byte(code: u16, value: &Vec<u8>) -> Self {
Tag::new(code, value.to_owned(), 1)
pub fn byte(code: u16, value: &[u8]) -> Self {
Tag::new(code, value.to_vec(), 1)
}
pub fn ascii(code: u16, value: &str) -> Self {
+30 -25
View File
@@ -6,7 +6,7 @@ use pyo3::prelude::*;
impl From<crate::error::Error> for PyErr {
fn from(err: crate::error::Error) -> PyErr {
PyErr::new::<PyValueError, _>(err.to_string())
color_eyre::eyre::Report::from(err).into()
}
}
@@ -333,39 +333,44 @@ impl PyIJTiffFile {
}
macro_rules! impl_save {
($T:ty, $t:ident) => {
#[pymethods]
impl PyIJTiffFile {
fn $t(
&mut self,
frame: PyArrayLike2<$T, AllowTypeChange>,
c: usize,
t: usize,
z: usize,
) -> PyResult<()> {
if let Some(ijtifffile) = self.ijtifffile.as_mut() {
ijtifffile.save(frame.as_array(), c, t, z)?;
($($T:ty: $t:ident $(,)?)*) => {
$(
#[pymethods]
impl PyIJTiffFile {
fn $t(
&mut self,
frame: PyArrayLike2<$T, AllowTypeChange>,
c: usize,
t: usize,
z: usize,
) -> PyResult<()> {
if let Some(ijtifffile) = self.ijtifffile.as_mut() {
ijtifffile.save(frame.as_array(), c, t, z)?;
}
Ok(())
}
Ok(())
}
}
)*
};
}
impl_save!(u8, save_u8);
impl_save!(u16, save_u16);
impl_save!(u32, save_u32);
impl_save!(u64, save_u64);
impl_save!(i8, save_i8);
impl_save!(i16, save_i16);
impl_save!(i32, save_i32);
impl_save!(i64, save_i64);
impl_save!(f32, save_f32);
impl_save!(f64, save_f64);
impl_save! {
u8: save_u8,
u16: save_u16,
u32: save_u32,
u64: save_u64,
i8: save_i8,
i16: save_i16,
i32: save_i32,
i64: save_i64,
f32: save_f32,
f64: save_f64,
}
#[pymodule]
#[pyo3(name = "tiffwrite_rs")]
fn tiffwrite_rs(m: &Bound<'_, PyModule>) -> PyResult<()> {
color_eyre::install()?;
m.add_class::<PyTag>()?;
m.add_class::<PyIJTiffFile>()?;
Ok(())