1
- use std:: fmt:: { self , Display } ;
2
- use std:: path:: PathBuf ;
3
1
use pyo3:: prelude:: * ;
4
2
use pyo3:: wrap_pyfunction;
5
3
use shr_parser:: { SHRParser , SHRParsingType } ;
4
+ use std:: fmt:: { self , Display } ;
5
+ use std:: path:: PathBuf ;
6
6
7
7
/// An enum mirroring SHRParsingType for Python.
8
8
#[ pyclass( name = "SHRParsingType" , eq, eq_int) ]
@@ -31,7 +31,7 @@ impl TryFrom<PySHRParsingType> for SHRParsingType {
31
31
match value {
32
32
PySHRParsingType :: PEAK => Ok ( SHRParsingType :: Peak ) ,
33
33
PySHRParsingType :: MEAN => Ok ( SHRParsingType :: Mean ) ,
34
- PySHRParsingType :: LOW => Ok ( SHRParsingType :: Low ) ,
34
+ PySHRParsingType :: LOW => Ok ( SHRParsingType :: Low ) ,
35
35
}
36
36
}
37
37
}
@@ -41,7 +41,7 @@ impl Display for PySHRParsingType {
41
41
match self {
42
42
PySHRParsingType :: PEAK => write ! ( f, "SHRParsingType.PEAK" ) ,
43
43
PySHRParsingType :: MEAN => write ! ( f, "SHRParsingType.MEAN" ) ,
44
- PySHRParsingType :: LOW => write ! ( f, "SHRParsingType.LOW" ) ,
44
+ PySHRParsingType :: LOW => write ! ( f, "SHRParsingType.LOW" ) ,
45
45
}
46
46
}
47
47
}
@@ -86,9 +86,13 @@ impl PySHRParser {
86
86
fn new ( file_path : & str , parsing_type : PySHRParsingType ) -> PyResult < Self > {
87
87
let shr_parsing = SHRParsingType :: try_from ( parsing_type)
88
88
. 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
+ } )
92
96
}
93
97
94
98
fn __repr__ ( & self ) -> String {
@@ -100,9 +104,9 @@ impl PySHRParser {
100
104
}
101
105
102
106
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
+ } )
106
110
}
107
111
108
112
fn get_sweeps ( & self ) -> PyResult < Vec < PySHRSweep > > {
@@ -137,11 +141,11 @@ fn create_parser(file_path: &str, parsing_type: PySHRParsingType) -> PyResult<Py
137
141
}
138
142
139
143
/// A Python module implemented in Rust.
140
- #[ pymodule( name= "shr_parser" ) ]
144
+ #[ pymodule( name = "shr_parser" ) ]
141
145
fn shr_parser_py ( m : & Bound < PyModule > ) -> PyResult < ( ) > {
142
146
m. add_class :: < PySHRParser > ( ) ?;
143
147
m. add_class :: < PySHRSweep > ( ) ?;
144
148
m. add_class :: < PySHRParsingType > ( ) ?;
145
149
m. add_function ( wrap_pyfunction ! ( create_parser, m) ?) ?;
146
150
Ok ( ( ) )
147
- }
151
+ }
0 commit comments