File types (#506)

* File types

* Run prepare + fmt

* Switch to struct

* Update docker version
This commit is contained in:
Geometrically
2022-12-23 16:36:53 -07:00
committed by GitHub
parent 5f175141e1
commit fe256d6a62
15 changed files with 388 additions and 671 deletions

View File

@@ -460,6 +460,7 @@ impl From<QueryVersion> for Version {
hashes: f.hashes,
primary: f.primary,
size: f.size,
file_type: f.file_type,
})
.collect(),
dependencies: data
@@ -587,6 +588,8 @@ pub struct VersionFile {
pub primary: bool,
/// The size in bytes of the file
pub size: u32,
/// The type of the file
pub file_type: Option<FileType>,
}
/// A dendency which describes what versions are required, break support, or are optional to the
@@ -603,7 +606,7 @@ pub struct Dependency {
pub dependency_type: DependencyType,
}
#[derive(Serialize, Deserialize, Clone, Eq, PartialEq)]
#[derive(Serialize, Deserialize, Copy, Clone, Eq, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum VersionType {
Release,
@@ -628,7 +631,7 @@ impl VersionType {
}
}
#[derive(Serialize, Deserialize, Clone)]
#[derive(Serialize, Deserialize, Copy, Clone)]
#[serde(rename_all = "lowercase")]
pub enum DependencyType {
Required,
@@ -665,6 +668,31 @@ impl DependencyType {
}
}
#[derive(Serialize, Deserialize, Copy, Clone, Debug)]
#[serde(rename_all = "kebab-case")]
pub enum FileType {
RequiredResourcePack,
OptionalResourcePack,
Unknown,
}
impl std::fmt::Display for FileType {
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
fmt.write_str(self.as_str())
}
}
impl FileType {
// These are constant, so this can remove unnecessary allocations (`to_string`)
pub fn as_str(&self) -> &'static str {
match self {
FileType::RequiredResourcePack => "required-resource-pack",
FileType::OptionalResourcePack => "optional-resource-pack",
FileType::Unknown => "unknown",
}
}
}
/// A specific version of Minecraft
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq)]
#[serde(transparent)]