Skip to content

Commit

Permalink
Merge pull request #10 from azam/feature/remove-label-break
Browse files Browse the repository at this point in the history
Remove break labels in macros
  • Loading branch information
azam authored Apr 18, 2023
2 parents 33ddd83 + 9372a36 commit a38428a
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,20 +292,23 @@ azam_decode_uint_impl!(u128, 16);
macro_rules! azam_decode {
() => {Result::<()>::Ok(())};
($r:expr) => {Result::<()>::Ok(())};
($r:expr $(,$t:ty)*) => {
'block: {
use $crate::decode::AzamDecode;
let reader = &mut $r.as_bytes();
Ok((
($r:expr $(,$t:ty)*) => {{
use $crate::decode::AzamDecode;
let reader = &mut $r.as_bytes();
// Using loop hack to not to use break-labels.
// This might help when using strict clippy rules.
// https://github.com/rust-lang/rfcs/pull/2046
loop {
break Ok((
$(
match <$t>::azam_decode_read(reader) {
Ok(v) => v,
Err(e) => break 'block Err(e),
Err(e) => break Err(e),
}
),*
))
));
}
};
}};
}

/// Macro to decode Azam codec encoded stream to tuples of any types that implements the [`AzamDecode`] trait.
Expand All @@ -325,20 +328,23 @@ macro_rules! azam_decode {
macro_rules! azam_decode_read {
() => {Result::<()>::Ok(())};
($r:expr) => {Result::<()>::Ok(())};
($r:expr $(,$t:ty)*) => {
'block: {
use $crate::decode::AzamDecode;
let reader = $r;
Ok((
($r:expr $(,$t:ty)*) => {{
use $crate::decode::AzamDecode;
let reader = $r;
// Using loop hack to not to use break-labels.
// This might help when using strict clippy rules.
// https://github.com/rust-lang/rfcs/pull/2046
loop {
break Ok((
$(
match <$t>::azam_decode_read(reader) {
Ok(v) => v,
Err(e) => break 'block Err(e),
Err(e) => break Err(e),
}
),*
))
}
};
}};
}

#[cfg(test)]
Expand Down

0 comments on commit a38428a

Please sign in to comment.