-
Notifications
You must be signed in to change notification settings - Fork 9
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
Optimize read lid state function #545
Optimize read lid state function #545
Conversation
LidState::Unknown | ||
}; | ||
Ok(state) | ||
Ok(match lid_str.split_whitespace().last().unwrap() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would the unwrap crash acs if the lid file wasn't in the right file or doesn't exist?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be a safe assumption that it's in the correct format
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wait actually, could you do unwrap or error and set state = LidState::Unknown if it doesn't unwrap correctly otherwise return the state
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does not crash. The if statement before prevents the crash.
if !self.found_path {
return Ok(LidState::Unapplicable);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
Perfect PR. Works, Fixes issue, stays in scope, best solution. A+ work |
Reduced two contains checks into a single split_whitespace() call with a match statement. Fixes #465