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

Add support for min version #28

Merged
merged 1 commit into from
Apr 21, 2020
Merged

Add support for min version #28

merged 1 commit into from
Apr 21, 2020

Conversation

lu-zero
Copy link
Contributor

@lu-zero lu-zero commented Mar 8, 2020

No description provided.

@shssoichiro
Copy link
Contributor

Bump. Would it be possible for someone to take a look and review this?

src/lib.rs Outdated
Comment on lines 309 to 318
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");
Copy link
Collaborator

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.

Copy link
Contributor Author

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
Comment on lines 327 to 335
} else {
Ok(())
}
}
} else {
Ok(())
}
}
Err(err) => Err(err)?,
Copy link
Collaborator

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 {
Copy link
Collaborator

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

Copy link
Contributor Author

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.

@lu-zero
Copy link
Contributor Author

lu-zero commented Apr 13, 2020

Made a bit simpler, I did not use regex to keep nasm-rs as lean as possible.

Copy link
Collaborator

@jrasky jrasky left a 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.

Comment on lines +318 to +326
} else {
if major > ver[0] ||
(major == ver[0] && minor > ver[1]) ||
(major == ver[0] && minor == ver[1] && micro > ver[2]) {
Err(version)?
} else {
Ok(())
}
}
Copy link
Collaborator

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,

@jrasky jrasky merged commit 72b23a1 into medek:master Apr 21, 2020
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.

3 participants