Skip to content

Consider getting rid of toolchain_sort() #3884

@rami3l

Description

@rami3l

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions