Skip to content

Commit 1f51945

Browse files
committed
make check_null_bytes less golfy
1 parent 5a69542 commit 1f51945

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/util.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,15 @@ pub(crate) fn ensure_compatible_types<T, E>() -> Result<(), Error> {
1414
/// If any `b'\0'` at positions other than the last byte are found, an error is returned. Otherwise
1515
/// `true` will be returned only if the last byte is `b'\0'`.
1616
pub(crate) fn check_null_bytes(data: &[u8]) -> Result<bool, Error> {
17-
let Some((last, remainder)) = data.split_last() else { return Ok(false) };
18-
(!remainder.contains(&0)).then_some(*last == 0).ok_or(Error::InteriorZeroElements)
17+
if let [rest @ .., last] = data {
18+
if rest.contains(&0) {
19+
Err(Error::InteriorZeroElements)
20+
} else {
21+
Ok(*last == 0)
22+
}
23+
} else {
24+
Ok(false)
25+
}
1926
}
2027

2128
/// This function copies the slice into a vec and appends an element to its end.

0 commit comments

Comments
 (0)