Last active
November 19, 2023 13:33
-
-
Save elenakrittik/c75299f22914f346536482ebac467dc9 to your computer and use it in GitHub Desktop.
Snippet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Dependencies: `versions` (for the `Versioning` struct), `ahash` (for `AHashMap`). | |
| // A mapping of "major.minor" to a struct representing "major.minor[.patch]" | |
| let mut latest_versions: AHashMap<&str, Versioning> = AHashMap::new(); | |
| // Not the code i am proud of, i must admit, but at least it works. | |
| // For each Godot version fetched from tuxfamily | |
| for godot_version in VERSIONS { | |
| for stable_godot_version in &STABLES { | |
| // We check if it is one of the versions marked as stable in our | |
| // custom data set | |
| if godot_version.starts_with(stable_godot_version) { | |
| // If yes, we check if we already have a version set as | |
| // "latest" in our hashmap. | |
| let latest: Option<&Versioning> = latest_versions.get(stable_godot_version); | |
| match latest { | |
| Some(latest) => { | |
| // If yes, we compare our currently-iterated-over version | |
| // with the one in the hashmap, and if it is greater, we | |
| // set it as the latest | |
| let godot_version = Versioning::new(godot_version.as_str()).unwrap(); | |
| if &godot_version > latest { | |
| latest_versions.insert(stable_godot_version, godot_version); | |
| } | |
| }, | |
| // If not, we simply set it as the latest. | |
| None => { latest_versions.insert(stable_godot_version, Versioning::new(godot_version.as_str()).unwrap()); }, | |
| } | |
| } | |
| } | |
| } | |
| VERSIONS = latest_versions.values().into_iter().map(|v| v.to_string()).collect(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment