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

Refactor for hax: avoid explicit return calls #150

Merged
merged 7 commits into from
Nov 21, 2023

Conversation

geonnave
Copy link
Collaborator

This is on top of #149.

@geonnave geonnave force-pushed the refactor-hax-returns branch from 5e6a208 to 6601062 Compare November 20, 2023 17:33
if let Ok((label, is_critical)) = res {
if buffer.len() > 1 {
// EAD value is present
let slice = &buffer[1..buffer.len()];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is replacing an explicit panic from .get() with an implicit one.

If you want to cut down panic options, could replace the [1..buffer.len()] with [1..] as a start, but you can also take it further and start with

if let Ok((&first, tail)) = buffer.split_first() {
    /* use first */
    /* no need for buffer.len() > 1, but go right with: */
    if Ok((&label, slice)) = tail.split_first() {
        /* use CBOR decoder on label or err out */
        /* slice here contains exactly what the annotated line panicingly  */
    }
} else {
    Err(...)
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I thought of [1..] on the way back home 🙃, but not the second one. Updated.

@geonnave geonnave merged commit 6d087d5 into openwsn-berkeley:main Nov 21, 2023
@geonnave geonnave deleted the refactor-hax-returns branch November 21, 2023 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants