lasprs 0.14.1

Library for Acoustic Signal Processing (Rust edition, with optional Python bindings via pyo3)
use super::*;
use crate::{filter::FilterError, *};
use snafu::prelude::*;

#[cfg_attr(
    feature = "python-bindings",
    gen_stub_pyclass_complex_enum,
    pyclass(from_py_object)
)]
#[allow(missing_docs)]
#[derive(Debug, Snafu, Clone, PartialEq)]
#[snafu(visibility(pub(crate)))]
pub enum SiggenError {
    #[snafu(display(
        "The current signal generator settings are incompatible with the stream sampling frequency. Sample rate too low: {}",
        fs
    ))]
    SampleRateTooLow { fs: Flt },
    #[snafu(display("invalid parameter: {}. {}.", param, criterion))]
    InvalidParameter { param: String, criterion: String },

    #[snafu(display("parameter {} is out of range: {}", parameter, source))]
    ParameterOutOfRange {
        source: ValidationError,
        parameter: String,
    },

    #[snafu(display("channel {} is out of range. Highest channel is: {}", channel, nchannels-1))]
    ChannelOutOfRange { channel: usize, nchannels: usize },

    #[snafu(display("equalizer could not be created due to error: {}", source))]
    EqualizerError {
        #[snafu(source)]
        source: FilterError,
    },
}

cfg_select! {
    feature = "python-bindings" => {
        use pyo3::exceptions::PyException;
        use std::fmt::{Display, Formatter};
        #[gen_stub_pyclass]
        #[pyclass(extends = PyException, str, from_py_object)] // or PyBaseException
        /// Wrapper for StreamMgrError, to make it a struct, not enum, as enums cannot
        /// be extended from PyBaseException.
        #[derive(Debug, Clone)]
        pub struct PySiggenError {
            /// The inner error
            #[pyo3(get)]
            pub inner: SiggenError,
        }
        impl Display for PySiggenError {
            fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
                write!(f, "{}", self.inner)
            }
        }
        #[gen_stub_pymethods]
        #[pymethods]
        impl PySiggenError {
            /// Create a new PyStreamMgrError from a StreamMgrError
            #[new]
            fn new(inner: SiggenError) -> Self {
                PySiggenError { inner }
            }
        }

        impl From<SiggenError> for PyErr {
            fn from(value: SiggenError) -> Self {
                // let err = PyStreamMgrError {inner: value};
                // PyErr::from_value(err.into())
                PyErr::new::<PySiggenError, _>(value)
            }
        }
    },
    _ => {}
}