Skip to content

Consider getting rid of toolchain_sort() #3884

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

Closed
rami3l opened this issue Jun 17, 2024 · 0 comments · Fixed by #3892
Closed

Consider getting rid of toolchain_sort() #3884

rami3l opened this issue Jun 17, 2024 · 0 comments · Fixed by #3892
Milestone

Comments

@rami3l
Copy link
Member

rami3l commented Jun 17, 2024

While indeed the derived Ord instance are not used, I guess I was doing something idiomatic here (not entirely my fault, the function has been in existence way before #3518):

/// Sorts [`ToolchainName`]s in the following order:
/// 1. `stable`/`beta`/`nightly`-prefixed names, in this exact order.
/// 2. `X.Y.Z-suffix` names, sorted by semver rules on `X.Y.Z`, then by `suffix`.
/// 3. Other names, sorted alphanumerically.
pub(crate) fn toolchain_sort(v: &mut [ToolchainName]) {
v.sort_by_key(|name| {
let s = name.to_string();
if s.starts_with("stable") {
return (0, None, s);
}
if s.starts_with("beta") {
return (1, None, s);
}
if s.starts_with("nightly") {
return (2, None, s);
}
if let Some((ver_str, suffix)) = s.split_once('-') {
if let Ok(ver) = semver::Version::parse(ver_str) {
return (3, Some(ver), suffix.to_owned());
}
}
(4, None, s)
})
}

How about making use of that to write an actual Ord instance?

#3880 (comment)

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 a pull request may close this issue.

1 participant