Skip to content

Commit

Permalink
use if-let instead of unwrap
Browse files Browse the repository at this point in the history
  • Loading branch information
braddunbar committed Apr 21, 2024
1 parent a1d0cc6 commit 63bca89
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/bytes_mut.rs
Expand Up @@ -468,18 +468,17 @@ impl BytesMut {
/// assert_eq!(&buf[..], &[0x1, 0x1, 0x3, 0x3]);
/// ```
pub fn resize(&mut self, new_len: usize, value: u8) {
let additional = new_len.checked_sub(self.len());

if additional.is_none() {
let additional = if let Some(additional) = new_len.checked_sub(self.len()) {
additional
} else {
self.truncate(new_len);
return;
}
};

if additional == Some(0) {
if additional == 0 {
return;
}

let additional = additional.unwrap();
self.reserve(additional);
let dst = self.spare_capacity_mut().as_mut_ptr();
unsafe {
Expand Down

0 comments on commit 63bca89

Please sign in to comment.