implement PartialEq, Eq and Hash derive traits

This commit is contained in:
Moritz Hölting 2024-06-24 21:27:11 +02:00
parent 7efe73eb80
commit a2d20dab8e
9 changed files with 15 additions and 37 deletions

View File

@ -22,4 +22,4 @@ getset = "0.1.2"
serde = { version = "1.0.197", optional = true, features = ["derive"] } serde = { version = "1.0.197", optional = true, features = ["derive"] }
serde_json = "1.0.114" serde_json = "1.0.114"
tracing = "0.1.40" 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 }

View File

@ -10,7 +10,7 @@ use crate::util::{
#[allow(missing_docs)] #[allow(missing_docs)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum Execute { pub enum Execute {
Align(String, Box<Execute>), Align(String, Box<Execute>),
Anchored(String, Box<Execute>), Anchored(String, Box<Execute>),
@ -365,7 +365,7 @@ fn combine_conditions_commands(
#[allow(missing_docs)] #[allow(missing_docs)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum Condition { pub enum Condition {
Atom(String), Atom(String),
Not(Box<Condition>), Not(Box<Condition>),

View File

@ -15,7 +15,7 @@ use crate::{
/// Represents a command that can be included in a function. /// Represents a command that can be included in a function.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum Command { pub enum Command {
/// A command that is already formatted as a string. /// A command that is already formatted as a string.
Raw(String), Raw(String),

View File

@ -13,7 +13,7 @@ use super::command::Command;
/// Function that can be called by a command /// Function that can be called by a command
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[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 { pub struct Function {
commands: Vec<Command>, commands: Vec<Command>,
/// Name of the function /// Name of the function

View File

@ -17,7 +17,7 @@ use crate::{
/// A Minecraft datapack. /// A Minecraft datapack.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone)] #[derive(Debug, Clone, PartialEq, Eq)]
pub struct Datapack { pub struct Datapack {
// TODO: Support filter and overlays // TODO: Support filter and overlays
description: String, description: String,
@ -107,17 +107,9 @@ impl Datapack {
} }
/// Compile the pack into a virtual folder. /// 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] #[must_use]
#[tracing::instrument(level = "debug", skip(self))] #[tracing::instrument(level = "debug", skip(self))]
pub fn compile(&self, options: &CompileOptions) -> VFolder { 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); tracing::debug!("Compiling datapack: {:?}", self);
let compiler_state = Mutex::new(CompilerState::default()); let compiler_state = Mutex::new(CompilerState::default());

View File

@ -19,7 +19,7 @@ use std::{
/// Namespace of a datapack /// Namespace of a datapack
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone)] #[derive(Debug, Clone, PartialEq, Eq)]
pub struct Namespace { pub struct Namespace {
name: String, name: String,
functions: HashMap<String, Function>, functions: HashMap<String, Function>,

View File

@ -7,7 +7,7 @@ use crate::{
/// A tag for various types. /// A tag for various types.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Tag { pub struct Tag {
replace: bool, replace: bool,
values: Vec<TagValue>, values: Vec<TagValue>,
@ -98,7 +98,7 @@ impl ToString for TagType {
/// The value of a tag. /// The value of a tag.
#[allow(clippy::module_name_repetitions)] #[allow(clippy::module_name_repetitions)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum TagValue { pub enum TagValue {
/// A simple value, either a resource location or an id of another tag. /// A simple value, either a resource location or an id of another tag.
Simple(String), Simple(String),

View File

@ -1,10 +1,10 @@
//! Compile options for the compiler. //! Compile options for the compiler.
use std::{ops::RangeInclusive, sync::Mutex}; use std::sync::Mutex;
use getset::Getters; use getset::Getters;
use crate::{datapack::Function, prelude::Datapack}; use crate::datapack::Function;
use super::extendable_queue::ExtendableQueue; use super::extendable_queue::ExtendableQueue;
@ -15,33 +15,19 @@ use super::extendable_queue::ExtendableQueue;
pub struct CompileOptions { pub struct CompileOptions {
/// Whether to compile in debug mode. /// Whether to compile in debug mode.
pub(crate) debug: bool, pub(crate) debug: bool,
/// Pack format of the datapack.
pub(crate) pack_formats: RangeInclusive<u8>,
} }
impl CompileOptions { impl CompileOptions {
/// Set whether to compile in debug mode. /// Set whether to compile in debug mode.
#[must_use] #[must_use]
pub fn with_debug(self, debug: bool) -> Self { pub fn with_debug(self, debug: bool) -> Self {
Self { debug, ..self } Self { debug }
}
/// Set the pack format of the datapack.
#[must_use]
pub fn with_pack_formats(self, pack_formats: RangeInclusive<u8>) -> Self {
Self {
pack_formats,
..self
}
} }
} }
impl Default for CompileOptions { impl Default for CompileOptions {
fn default() -> Self { fn default() -> Self {
Self { Self { debug: true }
debug: true,
pack_formats: Datapack::LATEST_FORMAT..=Datapack::LATEST_FORMAT,
}
} }
} }

View File

@ -7,7 +7,7 @@ use zip::ZipWriter;
/// Folder representation in virtual file system /// Folder representation in virtual file system
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Default, Clone)] #[derive(Debug, Default, Clone, PartialEq, Eq)]
pub struct VFolder { pub struct VFolder {
folders: HashMap<String, VFolder>, folders: HashMap<String, VFolder>,
files: HashMap<String, VFile>, files: HashMap<String, VFile>,
@ -304,7 +304,7 @@ impl TryFrom<&Path> for VFolder {
/// File representation in virtual file system /// File representation in virtual file system
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone)] #[derive(Debug, Clone, PartialEq, Eq)]
pub enum VFile { pub enum VFile {
/// Text file /// Text file
Text(String), Text(String),