@@ -114,10 +114,7 @@ impl VanillaExtractor {
114
114
return Ok ( ( ) ) ;
115
115
}
116
116
117
- let result = std:: fs:: create_dir_all ( path) ;
118
- if result. is_err ( ) {
119
- return Err ( ParseError ( format ! ( "Failed to create directory structure: {}" , result. unwrap_err( ) ) ) ) ;
120
- }
117
+ std:: fs:: create_dir_all ( path) . or_else ( |e| Err ( ParseError ( format ! ( "Failed to create directory structure: {}" , e) ) ) ) ?;
121
118
122
119
Ok ( ( ) )
123
120
}
@@ -134,9 +131,7 @@ impl VanillaExtractor {
134
131
org_path. push ( self . data_base_dir . clone ( ) ) ;
135
132
org_path. push ( "Org/" ) ;
136
133
137
- if self . deep_create_dir_if_not_exists ( org_path. clone ( ) ) . is_err ( ) {
138
- return Err ( ParseError ( "Failed to create directory structure." . to_string ( ) ) ) ;
139
- }
134
+ self . deep_create_dir_if_not_exists ( org_path. clone ( ) ) ?;
140
135
141
136
org_path. push ( format ! ( "{}.org" , org. name) ) ;
142
137
@@ -169,29 +164,19 @@ impl VanillaExtractor {
169
164
let mut data_path = self . root . clone ( ) ;
170
165
data_path. push ( self . data_base_dir . clone ( ) ) ;
171
166
172
- if self . deep_create_dir_if_not_exists ( data_path. clone ( ) ) . is_err ( ) {
173
- return Err ( ParseError ( "Failed to create data directory structure." . to_string ( ) ) ) ;
174
- }
167
+ self . deep_create_dir_if_not_exists ( data_path. clone ( ) ) ?;
175
168
176
169
data_path. push ( format ! ( "{}.pbm" , bitmap. name) ) ;
177
170
178
- let file = std:: fs:: File :: create ( data_path) ;
179
- if file. is_err ( ) {
180
- return Err ( ParseError ( "Failed to create bitmap file." . to_string ( ) ) ) ;
181
- }
182
-
183
- let mut file = file. unwrap ( ) ;
171
+ let mut file = std:: fs:: File :: create ( data_path) . or_else ( |e| Err ( ParseError ( format ! ( "Failed to create bitmap file: {}." , e) ) ) ) ?;
184
172
185
173
file. write_u8 ( 0x42 ) ?; // B
186
174
file. write_u8 ( 0x4D ) ?; // M
187
175
file. write_u32 :: < LE > ( bitmap. bytes . len ( ) as u32 + 0xE ) ?; // Size of BMP file
188
176
file. write_u32 :: < LE > ( 0 ) ?; // unused null bytes
189
177
file. write_u32 :: < LE > ( 0x76 ) ?; // Bitmap data offset (hardcoded for now, might wanna get the actual offset)
190
178
191
- let result = file. write_all ( & bitmap. bytes ) ;
192
- if result. is_err ( ) {
193
- return Err ( ParseError ( "Failed to write bitmap file." . to_string ( ) ) ) ;
194
- }
179
+ file. write_all ( & bitmap. bytes ) . or_else ( |e| Err ( ParseError ( format ! ( "Failed to write bitmap file: {}." , e) ) ) ) ?;
195
180
196
181
println ! ( "Extracted bitmap file: {}" , bitmap. name) ;
197
182
}
@@ -253,24 +238,13 @@ impl VanillaExtractor {
253
238
let mut stage_tbl_path = self . root . clone ( ) ;
254
239
stage_tbl_path. push ( self . data_base_dir . clone ( ) ) ;
255
240
256
- if self . deep_create_dir_if_not_exists ( stage_tbl_path. clone ( ) ) . is_err ( ) {
257
- return Err ( ParseError ( "Failed to create data directory structure." . to_string ( ) ) ) ;
258
- }
241
+ self . deep_create_dir_if_not_exists ( stage_tbl_path. clone ( ) ) ?;
259
242
260
243
stage_tbl_path. push ( "stage.sect" ) ;
261
244
262
- let mut stage_tbl_file = match std:: fs:: File :: create ( stage_tbl_path) {
263
- Ok ( file) => file,
264
- Err ( _) => {
265
- return Err ( ParseError ( "Failed to create stage table file." . to_string ( ) ) ) ;
266
- }
267
- } ;
268
-
269
- let result = stage_tbl_file. write_all ( byte_slice) ;
270
- if result. is_err ( ) {
271
- return Err ( ParseError ( "Failed to write to stage table file." . to_string ( ) ) ) ;
272
- }
245
+ let mut stage_tbl_file = std:: fs:: File :: create ( stage_tbl_path) . or_else ( |e| Err ( ParseError ( format ! ( "Failed to create stage table file: {}." , e) ) ) ) ?;
273
246
247
+ stage_tbl_file. write_all ( byte_slice) . or_else ( |e| Err ( ParseError ( format ! ( "Failed to write to stage table file: {}." , e) ) ) ) ?;
274
248
Ok ( ( ) )
275
249
}
276
250
}
0 commit comments