Handle basic constructor and generic FromStr for MinecraftVersion

This commit is contained in:
2025-12-03 00:03:08 +01:00
parent 9b68b3c487
commit 2152cb7926
3 changed files with 87 additions and 2 deletions

View File

@@ -108,3 +108,19 @@ impl FromStr for Snapshot {
Ok(Self { year, week, build })
}
}
impl FromStr for MinecraftVersion {
type Err = VersionError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
if let Ok(ver) = Version::from_str(s) {
return Ok(MinecraftVersion::Release(ver));
}
if let Ok(snap) = Snapshot::from_str(s) {
return Ok(MinecraftVersion::Snapshot(snap));
}
Err(VersionError::UnknownVersionFormat(s.to_string()))
}
}