Skip to content

Commit

Permalink
Thiserror and remove demo python code
Browse files Browse the repository at this point in the history
  • Loading branch information
nils-werner committed Dec 10, 2023
1 parent e514a2d commit 8c4d927
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 21 deletions.
21 changes: 21 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rir_generator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ edition = "2021"
[dependencies]
itertools = "0.10.5"
ndarray = "0.15.6"
thiserror = "1.0.50"
21 changes: 7 additions & 14 deletions rir_generator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
extern crate itertools;

use ndarray;
use thiserror::Error;
use std::f64::consts::PI;
use std::f64::EPSILON;
use std::fmt;

#[derive(Debug, Clone)]
pub enum MicrophoneType {
Expand All @@ -27,21 +27,14 @@ impl Into<f64> for MicrophoneType {
}
}

#[derive(Debug, Clone)]
pub struct BadCharError {
pub char: char,
}

impl std::error::Error for BadCharError {}

impl fmt::Display for BadCharError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Incorrect microphone character {}", self.char)
}
#[derive(Error, Debug)]
pub enum MicrophoneTypeError {
#[error("Incorrect microphone character {0}")]
BadCharError(char)
}

impl TryFrom<char> for MicrophoneType {
type Error = BadCharError;
type Error = MicrophoneTypeError;

fn try_from(x: char) -> Result<Self, Self::Error> {
match x {
Expand All @@ -50,7 +43,7 @@ impl TryFrom<char> for MicrophoneType {
'c' => Ok(Self::Cardioid),
's' => Ok(Self::Subcardioid),
'o' => Ok(Self::Omnidirectional),
_ => Err(BadCharError { char: x }),
_ => Err(Self::Error::BadCharError(x)),
}
}
}
Expand Down
7 changes: 0 additions & 7 deletions rir_generator_py/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@ use pyo3::exceptions::PyValueError;
use pyo3::prelude::*;
use rir_generator;

/// Formats the sum of two numbers as string.
#[pyfunction]
fn sum_as_string(a: usize, b: usize) -> PyResult<String> {
Ok((a + b).to_string())
}

#[pyfunction]
fn compute_rir(
_py: Python,
Expand Down Expand Up @@ -48,7 +42,6 @@ fn compute_rir(
/// A Python module implemented in Rust.
#[pymodule]
fn rir_generator_py(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_function(wrap_pyfunction!(sum_as_string, m)?)?;
m.add_function(wrap_pyfunction!(compute_rir, m)?)?;
Ok(())
}

0 comments on commit 8c4d927

Please sign in to comment.