Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove break labels in macros #10

Merged
merged 1 commit into from
Apr 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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