Skip to content

Commit

Permalink
Use let-else in buf_get_impl
Browse files Browse the repository at this point in the history
I think let-else is a bit more explicit here.
  • Loading branch information
braddunbar committed Dec 19, 2023
1 parent 72cbb92 commit 030dd21
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/buf/buf_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ macro_rules! buf_get_impl {
// It seems to be linked to the way the method is optimised by the compiler
let mut buf = [0; SIZE];

let subslice = match buf.get_mut(..$len_to_read) {
Some(subslice) => subslice,
None => panic_does_not_fit(SIZE, $len_to_read),
let Some(subslice) = buf.get_mut(..$len_to_read) else {
panic_does_not_fit(SIZE, $len_to_read);
};

$this.copy_to_slice(subslice);
Expand All @@ -55,9 +54,8 @@ macro_rules! buf_get_impl {
(be => $this:ident, $typ:tt, $len_to_read:expr) => {{
const SIZE: usize = core::mem::size_of::<$typ>();

let slice_at = match SIZE.checked_sub($len_to_read) {
Some(slice_at) => slice_at,
None => panic_does_not_fit(SIZE, $len_to_read),
let Some(slice_at) = SIZE.checked_sub($len_to_read) else {
panic_does_not_fit(SIZE, $len_to_read);
};

let mut buf = [0; SIZE];
Expand Down

0 comments on commit 030dd21

Please sign in to comment.