Skip to content

Commit 153b0ed

Browse files
committed
Use ok_or_else
1 parent 9114556 commit 153b0ed

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

crates/iceberg/src/puffin/metadata.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,9 @@ impl FileMetadata {
185185
- usize::from(FileMetadata::FOOTER_STRUCT_FLAGS_LENGTH)
186186
+ usize::from(byte_number);
187187

188-
let mut flag_byte = match footer_bytes.get(byte_offset) {
189-
None => Err(Error::new(
190-
ErrorKind::DataInvalid,
191-
"Index range is out of bounds.",
192-
)),
193-
Some(byte) => Ok(*byte),
194-
}?;
188+
let mut flag_byte = *footer_bytes.get(byte_offset).ok_or_else(|| {
189+
Error::new(ErrorKind::DataInvalid, "Index range is out of bounds.")
190+
})?;
195191
let mut bit_number = 0;
196192
while flag_byte != 0 {
197193
if flag_byte & 0x1 != 0 {
@@ -229,13 +225,9 @@ impl FileMetadata {
229225
let start_offset = usize::from(FileMetadata::MAGIC_LENGTH);
230226
let end_offset =
231227
usize::from(FileMetadata::MAGIC_LENGTH) + usize::try_from(footer_payload_length)?;
232-
let footer_payload_bytes = match footer_bytes.get(start_offset..end_offset) {
233-
None => Err(Error::new(
234-
ErrorKind::DataInvalid,
235-
"Index range is out of bounds.",
236-
)),
237-
Some(data) => Ok(data),
238-
}?;
228+
let footer_payload_bytes = footer_bytes
229+
.get(start_offset..end_offset)
230+
.ok_or_else(|| Error::new(ErrorKind::DataInvalid, "Index range is out of bounds."))?;
239231
let decompressed_footer_payload_bytes =
240232
footer_compression_codec.decompress(footer_payload_bytes.into())?;
241233

0 commit comments

Comments
 (0)