-
Notifications
You must be signed in to change notification settings - Fork 18
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
Add support for min version #28
Conversation
Bump. Would it be possible for someone to take a look and review this? |
src/lib.rs
Outdated
let ver: Vec<u8> = version | ||
.split(" ") | ||
.skip(2) | ||
.next() | ||
.map(|ver| { | ||
ver.split(".") | ||
.map(|v| v.parse().expect("Invalid version component")) | ||
.collect() | ||
}) | ||
.expect("Invalid version"); |
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.
There has to be a better way, I have no idea looking at this what this parsing does. My feeling is that some sort of regex may be a better solution.
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.
the regex is big, we can use it, but isn't exactly optimal.
src/lib.rs
Outdated
} else { | ||
Ok(()) | ||
} | ||
} | ||
} else { | ||
Ok(()) | ||
} | ||
} | ||
Err(err) => Err(err)?, |
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.
All this can probably be unrolled using the ?
operator, rather than all these nested if statements. Several test cases, each of which returns Err
if it fails.
src/lib.rs
Outdated
@@ -180,6 +182,12 @@ impl Build { | |||
self | |||
} | |||
|
|||
/// Set the minimum version required | |||
pub fn min_version(&mut self, major: u8, minor: u8, micro: u8) -> &mut Self { |
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.
Why u8
here? I feel like it can only cause problems to not just use usize
in this case
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.
sure, it can be changed that way.
Made a bit simpler, I did not use regex to keep nasm-rs as lean as possible. |
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.
One non-critical comment, LGTM.
} else { | ||
if major > ver[0] || | ||
(major == ver[0] && minor > ver[1]) || | ||
(major == ver[0] && minor == ver[1] && micro > ver[2]) { | ||
Err(version)? | ||
} else { | ||
Ok(()) | ||
} | ||
} |
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.
Since the previous if statement panic!
s, this code doesn't need an explicit else branch,
No description provided.