lasprs 0.8.0

Library for Acoustic Signal Processing (Rust edition, with optional Python bindings via pyo3)
Documentation
use crate::config::*;
use std::default;

/// Speed with which the PPM level meters drop after a peak
#[cfg_attr(feature = "python-bindings", pyclass(eq))]
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
#[repr(usize)]
pub enum PPMDropSpeed {
    /// Drop the level with approx 10 dB/s after a peak
    DropSpeed10dBps = 10,
    /// Drop the level with approx 20 dB/s after a peak
    #[default]
    DropSpeed20dBps = 20,
    /// Drop the level with approx 40 dB/s after a peak
    DropSpeed40dBps = 40,
}

#[cfg(feature = "python-bindings")]
#[cfg_attr(feature = "python-bindings", pymethods)]
impl PPMDropSpeed {
    fn __str__(&self) -> String {
        match self {
            PPMDropSpeed::DropSpeed10dBps => "10 dB/s".into(),
            PPMDropSpeed::DropSpeed20dBps => "20 dB/s".into(),
            PPMDropSpeed::DropSpeed40dBps => "40 dB/s".into(),
        }
    }
    #[staticmethod]
    fn all() -> Vec<PPMDropSpeed> {
        use PPMDropSpeed::*;
        vec![DropSpeed10dBps, DropSpeed20dBps, DropSpeed40dBps]
    }
    #[staticmethod]
    #[pyo3(name = "from_usize")]
    fn from_usize_py(val: usize) -> PPMDropSpeed {
        Self::from_usize(val)
    }
    #[staticmethod]
    #[pyo3(name = "default")]
    fn default_py() -> Self {
        Self::default()
    }
    #[pyo3(name = "to_usize")]
    #[allow(clippy::wrong_self_convention)]
    fn to_usize_py(&self) -> usize {
        self.to_usize()
    }
}

/// A simple way of serializing enums that are represented by an usize
pub trait FromToUsize {
    /// Convert value to usize
    fn to_usize(&self) -> usize;
    /// Create value from usize
    fn from_usize(uz: usize) -> Self;
}
impl FromToUsize for PPMDropSpeed {
    #[inline]
    fn to_usize(&self) -> usize {
        *self as usize
    }

    #[inline]
    fn from_usize(uz: usize) -> Self {
        match uz {
            10 => PPMDropSpeed::DropSpeed10dBps,
            20 => PPMDropSpeed::DropSpeed20dBps,
            40 => PPMDropSpeed::DropSpeed40dBps,
            _ => panic!("Not implemented drop speed"),
        }
    }
}
impl FromToUsize for Option<PPMDropSpeed> {
    #[inline]
    fn to_usize(&self) -> usize {
        match self {
            Some(dw) => *dw as usize,
            None => 0,
        }
    }

    #[inline]
    fn from_usize(uz: usize) -> Self {
        match uz {
            0 => None,
            i => Some(PPMDropSpeed::from_usize(i)),
        }
    }
}