From a2d20dab8ea97bbd873edafb23afaad34292457f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20H=C3=B6lting?= <87192362+moritz-hoelting@users.noreply.github.com> Date: Mon, 24 Jun 2024 21:27:11 +0200 Subject: [PATCH] implement PartialEq, Eq and Hash derive traits --- Cargo.toml | 2 +- src/datapack/command/execute.rs | 4 ++-- src/datapack/command/mod.rs | 2 +- src/datapack/function.rs | 2 +- src/datapack/mod.rs | 10 +--------- src/datapack/namespace.rs | 2 +- src/datapack/tag.rs | 4 ++-- src/util/compile.rs | 22 ++++------------------ src/virtual_fs.rs | 4 ++-- 9 files changed, 15 insertions(+), 37 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b67476d..e09077f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,4 +22,4 @@ getset = "0.1.2" serde = { version = "1.0.197", optional = true, features = ["derive"] } serde_json = "1.0.114" tracing = "0.1.40" -zip = { version = "1.1.1", default-features = false, features = ["deflate", "time"], optional = true } +zip = { version = "2.1.3", default-features = false, features = ["deflate", "time"], optional = true } diff --git a/src/datapack/command/execute.rs b/src/datapack/command/execute.rs index 12ccd97..a97004b 100644 --- a/src/datapack/command/execute.rs +++ b/src/datapack/command/execute.rs @@ -10,7 +10,7 @@ use crate::util::{ #[allow(missing_docs)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum Execute { Align(String, Box), Anchored(String, Box), @@ -365,7 +365,7 @@ fn combine_conditions_commands( #[allow(missing_docs)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum Condition { Atom(String), Not(Box), diff --git a/src/datapack/command/mod.rs b/src/datapack/command/mod.rs index 39e5243..248c9af 100644 --- a/src/datapack/command/mod.rs +++ b/src/datapack/command/mod.rs @@ -15,7 +15,7 @@ use crate::{ /// Represents a command that can be included in a function. #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum Command { /// A command that is already formatted as a string. Raw(String), diff --git a/src/datapack/function.rs b/src/datapack/function.rs index 2775e1c..3fe8392 100644 --- a/src/datapack/function.rs +++ b/src/datapack/function.rs @@ -13,7 +13,7 @@ use super::command::Command; /// Function that can be called by a command #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -#[derive(Debug, Clone, Default, Getters)] +#[derive(Debug, Clone, Default, Getters, PartialEq, Eq, Hash)] pub struct Function { commands: Vec, /// Name of the function diff --git a/src/datapack/mod.rs b/src/datapack/mod.rs index 3e7e3d3..e424139 100644 --- a/src/datapack/mod.rs +++ b/src/datapack/mod.rs @@ -17,7 +17,7 @@ use crate::{ /// A Minecraft datapack. #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Eq)] pub struct Datapack { // TODO: Support filter and overlays description: String, @@ -107,17 +107,9 @@ impl Datapack { } /// Compile the pack into a virtual folder. - /// - /// The pack format in the compile options will be overridden by the pack format of the datapack. #[must_use] #[tracing::instrument(level = "debug", skip(self))] pub fn compile(&self, options: &CompileOptions) -> VFolder { - let pack_formats = self - .supported_formats - .clone() - .unwrap_or(self.pack_format..=self.pack_format); - let options = &options.clone().with_pack_formats(pack_formats); - tracing::debug!("Compiling datapack: {:?}", self); let compiler_state = Mutex::new(CompilerState::default()); diff --git a/src/datapack/namespace.rs b/src/datapack/namespace.rs index cb634e7..540184a 100644 --- a/src/datapack/namespace.rs +++ b/src/datapack/namespace.rs @@ -19,7 +19,7 @@ use std::{ /// Namespace of a datapack #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Eq)] pub struct Namespace { name: String, functions: HashMap, diff --git a/src/datapack/tag.rs b/src/datapack/tag.rs index 190a03c..e16cd27 100644 --- a/src/datapack/tag.rs +++ b/src/datapack/tag.rs @@ -7,7 +7,7 @@ use crate::{ /// A tag for various types. #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct Tag { replace: bool, values: Vec, @@ -98,7 +98,7 @@ impl ToString for TagType { /// The value of a tag. #[allow(clippy::module_name_repetitions)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum TagValue { /// A simple value, either a resource location or an id of another tag. Simple(String), diff --git a/src/util/compile.rs b/src/util/compile.rs index a584634..ac1227d 100644 --- a/src/util/compile.rs +++ b/src/util/compile.rs @@ -1,10 +1,10 @@ //! Compile options for the compiler. -use std::{ops::RangeInclusive, sync::Mutex}; +use std::sync::Mutex; use getset::Getters; -use crate::{datapack::Function, prelude::Datapack}; +use crate::datapack::Function; use super::extendable_queue::ExtendableQueue; @@ -15,33 +15,19 @@ use super::extendable_queue::ExtendableQueue; pub struct CompileOptions { /// Whether to compile in debug mode. pub(crate) debug: bool, - /// Pack format of the datapack. - pub(crate) pack_formats: RangeInclusive, } impl CompileOptions { /// Set whether to compile in debug mode. #[must_use] pub fn with_debug(self, debug: bool) -> Self { - Self { debug, ..self } - } - - /// Set the pack format of the datapack. - #[must_use] - pub fn with_pack_formats(self, pack_formats: RangeInclusive) -> Self { - Self { - pack_formats, - ..self - } + Self { debug } } } impl Default for CompileOptions { fn default() -> Self { - Self { - debug: true, - pack_formats: Datapack::LATEST_FORMAT..=Datapack::LATEST_FORMAT, - } + Self { debug: true } } } diff --git a/src/virtual_fs.rs b/src/virtual_fs.rs index 4622c12..f047c73 100644 --- a/src/virtual_fs.rs +++ b/src/virtual_fs.rs @@ -7,7 +7,7 @@ use zip::ZipWriter; /// Folder representation in virtual file system #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -#[derive(Debug, Default, Clone)] +#[derive(Debug, Default, Clone, PartialEq, Eq)] pub struct VFolder { folders: HashMap, files: HashMap, @@ -304,7 +304,7 @@ impl TryFrom<&Path> for VFolder { /// File representation in virtual file system #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Eq)] pub enum VFile { /// Text file Text(String),