Skip to content

Commit 35c6265

Browse files
committed
Use map_err
1 parent 82e9eeb commit 35c6265

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

crates/iceberg/src/puffin/metadata.rs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -240,24 +240,16 @@ impl FileMetadata {
240240
let decompressed_footer_payload_bytes =
241241
footer_compression_codec.decompress(footer_payload_bytes.into())?;
242242

243-
match String::from_utf8(decompressed_footer_payload_bytes) {
244-
Err(src) => Err(Error::new(
245-
ErrorKind::DataInvalid,
246-
"Footer is not a valid UTF-8 string",
247-
)
248-
.with_source(src)),
249-
Ok(str) => Ok(str),
250-
}
243+
String::from_utf8(decompressed_footer_payload_bytes).map_err(|src| {
244+
Error::new(ErrorKind::DataInvalid, "Footer is not a valid UTF-8 string")
245+
.with_source(src)
246+
})
251247
}
252248

253249
fn from_json_str(string: &str) -> Result<FileMetadata> {
254-
match serde_json::from_str::<FileMetadata>(string) {
255-
Ok(file_metadata) => Ok(file_metadata),
256-
Err(src) => Err(
257-
Error::new(ErrorKind::DataInvalid, "Given string is not valid JSON")
258-
.with_source(src),
259-
),
260-
}
250+
serde_json::from_str::<FileMetadata>(string).map_err(|src| {
251+
Error::new(ErrorKind::DataInvalid, "Given string is not valid JSON").with_source(src)
252+
})
261253
}
262254

263255
/// Returns the file metadata about a Puffin file

0 commit comments

Comments
 (0)