Reduce the size of the simple version to 4 bytes

feature/lookup-installed
trivernis 1 year ago
parent 0e47ee75e7
commit 713310f9b8
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -16,7 +16,7 @@ use super::VersionInfo;
#[derive(Clone, Serialize, Deserialize)]
pub struct Versions {
lts_versions: HashMap<String, u16>,
lts_versions: HashMap<String, u8>,
versions: HashMap<SimpleVersion, VersionMetadata>,
// as this field is not serialized
// it needs to be calculated after serialization
@ -53,7 +53,7 @@ impl Versions {
pub fn new(all_versions: Vec<VersionInfo>) -> Self {
let lts_versions = all_versions
.iter()
.filter_map(|v| Some((v.lts.lts_ref()?.to_lowercase(), v.version.major as u16)))
.filter_map(|v| Some((v.lts.lts_ref()?.to_lowercase(), v.version.major as u8)))
.collect::<HashMap<_, _>>();
let mut sorted_versions = all_versions
.iter()
@ -133,7 +133,7 @@ impl Versions {
/// Returns any version that fulfills the given requirement
#[tracing::instrument(level = "debug", skip(self))]
fn get_latest_for_major(&self, major: u16) -> Option<&VersionMetadata> {
fn get_latest_for_major(&self, major: u8) -> Option<&VersionMetadata> {
let fulfilling_versions = self
.sorted_versions
.iter()

@ -6,9 +6,9 @@ use crate::repository::downloader::VersionInfo;
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Deserialize, Serialize, Hash)]
pub struct SimpleVersion {
pub major: u16,
pub minor: u16,
pub patch: u32,
pub major: u8,
pub minor: u8,
pub patch: u16,
}
#[derive(Clone, Serialize, Deserialize)]
@ -22,9 +22,9 @@ pub struct VersionMetadata {
impl From<semver::Version> for SimpleVersion {
fn from(value: semver::Version) -> Self {
Self {
major: value.major as u16,
minor: value.minor as u16,
patch: value.patch as u32,
major: value.major as u8,
minor: value.minor as u8,
patch: value.patch as u16,
}
}
}

Loading…
Cancel
Save