Rustic cleanups, dedups and making the code less hard to read in general (#251)

* typos :help_me:

* (part 1/?) massive cleanup to make the code more Rust-ic and cut down heap allocations.

* (part 2/?) massive cleanup to make the code more Rust-ic and cut down heap allocations.

* (part 3/?) cut down some pretty major heap allocations here - more Bytes and BytesMuts, less Vec<u8>s

also I don't really understand why you need to `to_vec` when you don't really use it again afterwards

* (part 4/?) deduplicate error handling in backblaze logic

* (part 5/?) fixes, cleanups, refactors, and reformatting

* (part 6/?) cleanups and refactors

* remove loads of `as_str` in types that already are `Display`

* Revert "remove loads of `as_str` in types that already are `Display`"

This reverts commit 4f974310cfb167ceba03001d81388db4f0fbb509.

* reformat and move routes util to the util module

* use streams

* Run prepare + formatting issues

Co-authored-by: Jai A <jaiagr+gpg@pm.me>
Co-authored-by: Geometrically <18202329+Geometrically@users.noreply.github.com>
This commit is contained in:
Leo Chen
2021-10-12 11:26:59 +08:00
committed by GitHub
parent 0010119440
commit 13187de97d
53 changed files with 997 additions and 1129 deletions

View File

@@ -3,18 +3,18 @@ use chrono::{DateTime, NaiveDateTime, Utc};
use std::io::Cursor;
use zip::ZipArchive;
pub struct ForgeValidator {}
pub struct ForgeValidator;
impl super::Validator for ForgeValidator {
fn get_file_extensions<'a>(&self) -> &'a [&'a str] {
fn get_file_extensions(&self) -> &[&str] {
&["jar", "zip"]
}
fn get_project_types<'a>(&self) -> &'a [&'a str] {
fn get_project_types(&self) -> &[&str] {
&["mod"]
}
fn get_supported_loaders<'a>(&self) -> &'a [&'a str] {
fn get_supported_loaders(&self) -> &[&str] {
&["forge"]
}
@@ -31,12 +31,12 @@ impl super::Validator for ForgeValidator {
archive: &mut ZipArchive<Cursor<&[u8]>>,
) -> Result<ValidationResult, ValidationError> {
archive.by_name("META-INF/mods.toml").map_err(|_| {
ValidationError::InvalidInputError("No mods.toml present for Forge file.".to_string())
ValidationError::InvalidInputError("No mods.toml present for Forge file.".into())
})?;
if !archive.file_names().any(|name| name.ends_with(".class")) {
return Ok(ValidationResult::Warning(
"Forge mod file is a source file!".to_string(),
"Forge mod file is a source file!".into(),
));
}
@@ -46,26 +46,26 @@ impl super::Validator for ForgeValidator {
}
}
pub struct LegacyForgeValidator {}
pub struct LegacyForgeValidator;
impl super::Validator for LegacyForgeValidator {
fn get_file_extensions<'a>(&self) -> &'a [&'a str] {
fn get_file_extensions(&self) -> &[&str] {
&["jar", "zip"]
}
fn get_project_types<'a>(&self) -> &'a [&'a str] {
fn get_project_types(&self) -> &[&str] {
&["mod"]
}
fn get_supported_loaders<'a>(&self) -> &'a [&'a str] {
fn get_supported_loaders(&self) -> &[&str] {
&["forge"]
}
fn get_supported_game_versions(&self) -> SupportedGameVersions {
// Times between versions 1.5.2 to 1.12.2, which all use the legacy way of defining mods
SupportedGameVersions::Range(
DateTime::<Utc>::from_utc(NaiveDateTime::from_timestamp(1366818300, 0), Utc),
DateTime::<Utc>::from_utc(NaiveDateTime::from_timestamp(1505810340, 0), Utc),
DateTime::from_utc(NaiveDateTime::from_timestamp(1366818300, 0), Utc),
DateTime::from_utc(NaiveDateTime::from_timestamp(1505810340, 0), Utc),
)
}
@@ -74,12 +74,12 @@ impl super::Validator for LegacyForgeValidator {
archive: &mut ZipArchive<Cursor<&[u8]>>,
) -> Result<ValidationResult, ValidationError> {
archive.by_name("mcmod.info").map_err(|_| {
ValidationError::InvalidInputError("No mcmod.info present for Forge file.".to_string())
ValidationError::InvalidInputError("No mcmod.info present for Forge file.".into())
})?;
if !archive.file_names().any(|name| name.ends_with(".class")) {
return Ok(ValidationResult::Warning(
"Forge mod file is a source file!".to_string(),
"Forge mod file is a source file!".into(),
));
}