v1?
This commit is contained in:
@@ -5,6 +5,25 @@ use std::{fs::File, path::PathBuf};
|
||||
#[derive(Debug, Deserialize, Clone)]
|
||||
pub struct LogFile(Vec<super::Game>);
|
||||
|
||||
impl LogFile {
|
||||
pub fn min_ver(&self) -> semver::Version {
|
||||
let mut lowest = semver::Version::new(u64::MAX, u64::MAX, u64::MAX);
|
||||
|
||||
self.0.iter().for_each(|x| {
|
||||
if x.version.cmp_precedence(&lowest).is_lt() {
|
||||
lowest = x.version.clone()
|
||||
}
|
||||
});
|
||||
|
||||
lowest
|
||||
}
|
||||
|
||||
/// Returns if the LogFile min version is compatible.
|
||||
pub fn is_compatible(&self) -> bool {
|
||||
self.min_ver().cmp_precedence(&super::MIN_VER).is_lt()
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<File> for LogFile {
|
||||
type Error = ron::error::SpannedError;
|
||||
|
||||
@@ -31,34 +50,3 @@ impl TryFrom<PathBuf> for LogFile {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl LogFile {
|
||||
pub fn get_min_ver(self) -> semver::Version {
|
||||
let mut lowest = semver::Version::new(u64::MAX, u64::MAX, u64::MAX);
|
||||
|
||||
self.0.iter().for_each(|x| {
|
||||
if x.version.cmp_precedence(&lowest).is_lt() {
|
||||
lowest = x.version.clone()
|
||||
}
|
||||
});
|
||||
|
||||
lowest
|
||||
}
|
||||
|
||||
/// Returns if the LogFile min version is compatible.
|
||||
fn is_compatible(&self) -> bool {
|
||||
self.clone()
|
||||
.get_min_ver()
|
||||
.cmp_precedence(&super::MIN_VER)
|
||||
.is_lt()
|
||||
}
|
||||
|
||||
/// Ensures that the returned gamefile is compatible, else returns Error.
|
||||
pub fn ensure_compatible(self) -> Result<Self, error::LogFileError> {
|
||||
if self.is_compatible() {
|
||||
Ok(self)
|
||||
} else {
|
||||
Err(error::LogFileError::CompatibilityCheck(self.get_min_ver()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user