Skip to content

Commit 5fdee1a

Browse files
committed
chore: fixed parsing type
1 parent ad98102 commit 5fdee1a

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

src/lib.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use std::fmt::{self, Display};
2-
use std::path::PathBuf;
31
use pyo3::prelude::*;
42
use pyo3::wrap_pyfunction;
53
use shr_parser::{SHRParser, SHRParsingType};
4+
use std::fmt::{self, Display};
5+
use std::path::PathBuf;
66

77
/// An enum mirroring SHRParsingType for Python.
88
#[pyclass(name = "SHRParsingType", eq, eq_int)]
@@ -31,7 +31,7 @@ impl TryFrom<PySHRParsingType> for SHRParsingType {
3131
match value {
3232
PySHRParsingType::PEAK => Ok(SHRParsingType::Peak),
3333
PySHRParsingType::MEAN => Ok(SHRParsingType::Mean),
34-
PySHRParsingType::LOW => Ok(SHRParsingType::Low),
34+
PySHRParsingType::LOW => Ok(SHRParsingType::Low),
3535
}
3636
}
3737
}
@@ -41,7 +41,7 @@ impl Display for PySHRParsingType {
4141
match self {
4242
PySHRParsingType::PEAK => write!(f, "SHRParsingType.PEAK"),
4343
PySHRParsingType::MEAN => write!(f, "SHRParsingType.MEAN"),
44-
PySHRParsingType::LOW => write!(f, "SHRParsingType.LOW"),
44+
PySHRParsingType::LOW => write!(f, "SHRParsingType.LOW"),
4545
}
4646
}
4747
}
@@ -86,9 +86,13 @@ impl PySHRParser {
8686
fn new(file_path: &str, parsing_type: PySHRParsingType) -> PyResult<Self> {
8787
let shr_parsing = SHRParsingType::try_from(parsing_type)
8888
.map_err(|e| pyo3::exceptions::PyValueError::new_err(e))?;
89-
let parser = SHRParser::new(PathBuf::from(file_path), shr_parsing)
90-
.map_err(|e| pyo3::exceptions::PyIOError::new_err(format!("Failed to parse SHR file: {:?}", e)))?;
91-
Ok(PySHRParser { parser, parsing_type })
89+
let parser = SHRParser::new(PathBuf::from(file_path), shr_parsing).map_err(|e| {
90+
pyo3::exceptions::PyIOError::new_err(format!("Failed to parse SHR file: {:?}", e))
91+
})?;
92+
Ok(PySHRParser {
93+
parser,
94+
parsing_type,
95+
})
9296
}
9397

9498
fn __repr__(&self) -> String {
@@ -100,9 +104,9 @@ impl PySHRParser {
100104
}
101105

102106
fn to_csv(&self, path: String) -> PyResult<()> {
103-
self.parser
104-
.to_csv(PathBuf::from(path))
105-
.map_err(|e| pyo3::exceptions::PyIOError::new_err(format!("Failed to write to CSV: {:?}", e)))
107+
self.parser.to_csv(PathBuf::from(path)).map_err(|e| {
108+
pyo3::exceptions::PyIOError::new_err(format!("Failed to write to CSV: {:?}", e))
109+
})
106110
}
107111

108112
fn get_sweeps(&self) -> PyResult<Vec<PySHRSweep>> {
@@ -137,11 +141,11 @@ fn create_parser(file_path: &str, parsing_type: PySHRParsingType) -> PyResult<Py
137141
}
138142

139143
/// A Python module implemented in Rust.
140-
#[pymodule(name="shr_parser")]
144+
#[pymodule(name = "shr_parser")]
141145
fn shr_parser_py(m: &Bound<PyModule>) -> PyResult<()> {
142146
m.add_class::<PySHRParser>()?;
143147
m.add_class::<PySHRSweep>()?;
144148
m.add_class::<PySHRParsingType>()?;
145149
m.add_function(wrap_pyfunction!(create_parser, m)?)?;
146150
Ok(())
147-
}
151+
}

0 commit comments

Comments
 (0)