Derive Clone, PartialEq, Eq, and Hash where appropriate.

This is really useful for anyone who wishes to use the steven_protocol
crate and write tests that compare packets to expected values.
This commit is contained in:
Ben Reeves 2022-01-17 22:59:25 -06:00 committed by iceiix
parent 00e7a3d1bc
commit 9a8d3572eb
11 changed files with 67 additions and 62 deletions

View File

@ -15,7 +15,7 @@
use std::fmt;
use std::mem;
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Component {
Text(TextComponent),
}
@ -115,7 +115,7 @@ impl Default for Component {
}
}
#[derive(Debug, Default, Clone)]
#[derive(Debug, Default, Clone, PartialEq, Eq)]
pub struct Modifier {
pub extra: Option<Vec<Component>>,
pub bold: Option<bool>,
@ -159,7 +159,7 @@ impl Modifier {
}
}
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TextComponent {
pub text: String,
pub modifier: Modifier,
@ -199,7 +199,7 @@ impl fmt::Display for TextComponent {
}
}
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Color {
Black,
DarkBlue,

View File

@ -17,7 +17,7 @@ use crate::protocol::{self, Serializable};
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use std::io;
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub struct Stack {
pub id: isize,
pub count: isize,

View File

@ -20,7 +20,7 @@ use super::protocol;
use super::protocol::Serializable;
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub enum Tag {
End,
Byte(i8),
@ -37,7 +37,7 @@ pub enum Tag {
LongArray(Vec<i64>),
}
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub struct NamedTag(pub String, pub Tag);
impl Tag {

View File

@ -5,7 +5,7 @@ use std::io;
use super::{Error, LenPrefixed, Serializable, VarInt};
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum Phase {
// Client handshake states (written)
Start,
@ -44,7 +44,7 @@ impl Serializable for Phase {
}
}
#[derive(Clone, Debug, Default)]
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct ForgeMod {
pub modid: String,
pub version: String,
@ -64,7 +64,7 @@ impl Serializable for ForgeMod {
}
}
#[derive(Debug)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ModIdMapping {
pub name: String,
pub id: VarInt,
@ -87,7 +87,7 @@ impl Serializable for ModIdMapping {
pub static BLOCK_NAMESPACE: &str = "\u{1}";
pub static ITEM_NAMESPACE: &str = "\u{2}";
#[derive(Debug)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum FmlHs {
ServerHello {
fml_protocol_version: i8,
@ -196,7 +196,7 @@ pub mod fml2 {
// https://wiki.vg/Minecraft_Forge_Handshake#FML2_protocol_.281.13_-_Current.29
use super::*;
#[derive(Clone, Default, Debug)]
#[derive(Clone, Default, Debug, PartialEq, Eq)]
pub struct Channel {
pub name: String,
pub version: String,
@ -216,7 +216,7 @@ pub mod fml2 {
}
}
#[derive(Clone, Default, Debug)]
#[derive(Clone, Default, Debug, PartialEq, Eq)]
pub struct Registry {
pub name: String,
pub marker: String,
@ -236,7 +236,7 @@ pub mod fml2 {
}
}
#[derive(Debug)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum FmlHandshake {
ModList {
mod_names: LenPrefixed<VarInt, String>,

View File

@ -75,7 +75,7 @@ macro_rules! state_packets {
use crate::protocol::*;
use std::io;
#[derive(Debug)]
#[derive(Debug, Clone, PartialEq)]
pub enum Packet {
$(
$(
@ -107,7 +107,7 @@ macro_rules! state_packets {
}
$(
#[derive(Default, Debug)]
#[derive(Default, Debug, Clone, PartialEq)]
$(#[$attr])* pub struct $name {
$($(#[$fattr])* pub $field: $field_type),+,
}
@ -418,7 +418,7 @@ impl Serializable for f64 {
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub struct UUID(u64, u64);
#[derive(Debug)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct UUIDParseError;
impl std::error::Error for UUIDParseError {}
@ -469,6 +469,7 @@ impl Serializable for UUID {
}
}
#[derive(Clone, PartialEq, Eq)]
pub struct Biomes3D {
pub data: [i32; 1024],
}
@ -511,6 +512,7 @@ pub trait Lengthable: Serializable + Copy + Default {
fn from_len(_: usize) -> Self;
}
#[derive(Clone, PartialEq, Eq)]
pub struct LenPrefixed<L: Lengthable, V> {
len: L,
pub data: Vec<V>,
@ -566,6 +568,7 @@ impl<L: Lengthable, V: fmt::Debug> fmt::Debug for LenPrefixed<L, V> {
}
// Optimization
#[derive(Clone, PartialEq, Eq)]
pub struct LenPrefixedBytes<L: Lengthable> {
len: L,
pub data: Vec<u8>,
@ -662,7 +665,7 @@ impl Lengthable for i32 {
use num_traits::cast::{cast, NumCast};
/// `FixedPoint5` has the 5 least-significant bits for the fractional
/// part, upper for integer part: https://wiki.vg/Data_types#Fixed-point_numbers
#[derive(Clone, Copy)]
#[derive(Clone, Copy, PartialEq, Eq)]
pub struct FixedPoint5<T>(T);
impl<T: Serializable> Serializable for FixedPoint5<T> {
@ -708,7 +711,7 @@ where
}
/// `FixedPoint12` is like `FixedPoint5` but the fractional part is 12-bit
#[derive(Clone, Copy)]
#[derive(Clone, Copy, PartialEq, Eq)]
pub struct FixedPoint12<T>(T);
impl<T: Serializable> Serializable for FixedPoint12<T> {
@ -755,7 +758,7 @@ where
/// `VarInt` have a variable size (between 1 and 5 bytes) when encoded based
/// on the size of the number
#[derive(Clone, Copy)]
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub struct VarInt(pub i32);
impl Lengthable for VarInt {
@ -818,7 +821,7 @@ impl fmt::Debug for VarInt {
/// `VarShort` have a variable size (2 or 3 bytes) and are backwards-compatible
/// with vanilla shorts, used for Forge custom payloads
#[derive(Clone, Copy)]
#[derive(Clone, Copy, PartialEq, Eq)]
pub struct VarShort(pub i32);
impl Lengthable for VarShort {
@ -881,7 +884,7 @@ impl fmt::Debug for VarShort {
/// `VarLong` have a variable size (between 1 and 10 bytes) when encoded based
/// on the size of the number
#[derive(Clone, Copy)]
#[derive(Clone, Copy, PartialEq, Eq)]
pub struct VarLong(pub i64);
impl Lengthable for VarLong {
@ -963,7 +966,7 @@ impl Serializable for Position {
/// Direction is used to define whether packets are going to the
/// server or the client.
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Direction {
Serverbound,
Clientbound,
@ -1436,7 +1439,7 @@ pub fn try_parse_packet(ibuf: Vec<u8>, protocol_version: i32) {
}
}
#[derive(Debug)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Status {
pub version: StatusVersion,
pub players: StatusPlayers,
@ -1446,20 +1449,20 @@ pub struct Status {
pub fml_network_version: Option<i64>,
}
#[derive(Debug)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct StatusVersion {
pub name: String,
pub protocol: i32,
}
#[derive(Debug)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct StatusPlayers {
pub max: i32,
pub online: i32,
pub sample: Vec<StatusPlayer>,
}
#[derive(Debug)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct StatusPlayer {
name: String,
id: String,

View File

@ -16,7 +16,7 @@
use serde_json::json;
use sha1::{self, Digest};
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Profile {
pub username: String,
pub id: String,

View File

@ -2415,7 +2415,7 @@ state_packets!(
}
);
#[derive(Debug, Default)]
#[derive(Debug, Default, Clone, PartialEq, Eq)]
pub struct SpawnProperty {
pub name: String,
pub value: String,
@ -2438,7 +2438,7 @@ impl Serializable for SpawnProperty {
}
}
#[derive(Debug, Default)]
#[derive(Debug, Default, Clone, PartialEq, Eq)]
pub struct Statistic {
pub name: String,
pub value: VarInt,
@ -2458,7 +2458,7 @@ impl Serializable for Statistic {
}
}
#[derive(Debug, Default)]
#[derive(Debug, Default, Clone, PartialEq, Eq)]
pub struct BlockChangeRecord {
pub xz: u8,
pub y: u8,
@ -2481,7 +2481,7 @@ impl Serializable for BlockChangeRecord {
}
}
#[derive(Debug, Default)]
#[derive(Debug, Default, Clone, PartialEq, Eq)]
pub struct ChunkMeta {
pub x: i32,
pub z: i32,
@ -2504,7 +2504,7 @@ impl Serializable for ChunkMeta {
}
}
#[derive(Debug, Default)]
#[derive(Debug, Default, Clone, PartialEq, Eq)]
pub struct ExplosionRecord {
pub x: i8,
pub y: i8,
@ -2527,7 +2527,7 @@ impl Serializable for ExplosionRecord {
}
}
#[derive(Debug)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct MapIcon {
pub direction_type: i8,
pub x: i8,
@ -2560,7 +2560,7 @@ impl Default for MapIcon {
}
}
#[derive(Debug, Default)]
#[derive(Debug, Default, Clone, PartialEq)]
pub struct Advancement {
pub id: String,
pub parent_id: Option<String>,
@ -2613,7 +2613,7 @@ impl Serializable for Advancement {
}
}
#[derive(Debug, Default)]
#[derive(Debug, Default, Clone, PartialEq)]
pub struct AdvancementDisplay {
pub title: String,
pub description: String,
@ -2666,7 +2666,7 @@ impl Serializable for AdvancementDisplay {
}
}
#[derive(Debug, Default)]
#[derive(Debug, Default, Clone, PartialEq, Eq)]
pub struct AdvancementProgress {
pub id: String,
pub criteria: LenPrefixed<VarInt, CriterionProgress>,
@ -2686,7 +2686,7 @@ impl Serializable for AdvancementProgress {
}
}
#[derive(Debug, Default)]
#[derive(Debug, Default, Clone, PartialEq, Eq)]
pub struct CriterionProgress {
pub id: String,
pub date_of_achieving: Option<i64>,
@ -2714,7 +2714,7 @@ impl Serializable for CriterionProgress {
}
}
#[derive(Debug, Default)]
#[derive(Debug, Default, Clone, PartialEq)]
pub struct EntityEquipment {
pub slot: u8,
pub item: Option<item::Stack>,
@ -2735,7 +2735,7 @@ impl Serializable for EntityEquipment {
}
// Top-bit terminated array of EntityEquipment
#[derive(Debug, Default)]
#[derive(Debug, Default, Clone, PartialEq)]
pub struct EntityEquipments {
pub equipments: Vec<EntityEquipment>,
}
@ -2765,7 +2765,7 @@ impl Serializable for EntityEquipments {
}
}
#[derive(Debug, Default)]
#[derive(Debug, Default, Clone, PartialEq)]
pub struct EntityProperty {
pub key: String,
pub value: f64,
@ -2788,7 +2788,7 @@ impl Serializable for EntityProperty {
}
}
#[derive(Debug, Default)]
#[derive(Debug, Default, Clone, PartialEq)]
pub struct EntityProperty_i16 {
pub key: String,
pub value: f64,
@ -2811,7 +2811,7 @@ impl Serializable for EntityProperty_i16 {
}
}
#[derive(Debug, Default)]
#[derive(Debug, Default, Clone, PartialEq)]
pub struct PropertyModifier {
pub uuid: UUID,
pub amount: f64,
@ -2834,7 +2834,7 @@ impl Serializable for PropertyModifier {
}
}
#[derive(Debug)]
#[derive(Debug, Clone, PartialEq)]
pub struct PlayerInfoData {
pub action: VarInt,
pub players: Vec<PlayerDetail>,
@ -2920,7 +2920,7 @@ impl Default for PlayerInfoData {
}
}
#[derive(Debug)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum PlayerDetail {
Add {
uuid: UUID,
@ -2947,7 +2947,7 @@ pub enum PlayerDetail {
},
}
#[derive(Debug)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PlayerProperty {
pub name: String,
pub value: String,
@ -2957,7 +2957,7 @@ pub struct PlayerProperty {
use crate::item;
type RecipeIngredient = LenPrefixed<VarInt, Option<item::Stack>>;
#[derive(Debug)]
#[derive(Debug, Clone, PartialEq)]
pub enum RecipeData {
Shapeless {
group: String,
@ -3031,7 +3031,7 @@ impl Default for RecipeData {
}
}
#[derive(Debug, Default)]
#[derive(Debug, Default, Clone, PartialEq)]
pub struct Recipe {
pub id: String,
pub ty: String,
@ -3153,7 +3153,7 @@ impl Serializable for Recipe {
}
}
#[derive(Debug, Default)]
#[derive(Debug, Default, Clone, PartialEq, Eq)]
pub struct Tags {
pub tag_name: String,
pub entries: LenPrefixed<VarInt, VarInt>,
@ -3172,7 +3172,7 @@ impl Serializable for Tags {
}
}
#[derive(Debug, Default)]
#[derive(Debug, Default, Clone, PartialEq, Eq)]
pub struct TagsGroup {
pub tag_type: String,
pub tags: LenPrefixed<VarInt, Tags>,
@ -3191,7 +3191,7 @@ impl Serializable for TagsGroup {
}
}
#[derive(Debug, Default)]
#[derive(Debug, Default, Clone, PartialEq)]
pub struct Trade {
pub input_item_1: Option<nbt::NamedTag>,
pub output_item: Option<nbt::NamedTag>,
@ -3234,7 +3234,7 @@ impl Serializable for Trade {
}
}
#[derive(Debug, Default)]
#[derive(Debug, Default, Clone, PartialEq)]
pub struct CommandNode {
pub flags: u8,
pub children: LenPrefixed<VarInt, VarInt>,
@ -3245,14 +3245,14 @@ pub struct CommandNode {
pub suggestions_type: Option<String>,
}
#[derive(Debug, Eq, PartialEq)]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
enum CommandNodeType {
Root,
Literal,
Argument,
}
#[derive(Debug)]
#[derive(Debug, Clone, PartialEq)]
pub enum CommandProperty {
Bool,
Double {
@ -3484,7 +3484,7 @@ impl Serializable for CommandNode {
}
}
#[derive(Debug, Clone, Default)]
#[derive(Debug, Clone, Default, PartialEq)]
pub struct NumberedSlot {
pub slot_number: i16,
pub slot_data: Option<item::Stack>,

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Set {
data: Vec<u64>,
}

View File

@ -24,6 +24,7 @@ use std::fmt;
use std::io;
use std::marker::PhantomData;
#[derive(Clone, Copy, PartialEq, Eq)]
pub struct MetadataKey<T: MetaValue> {
index: i32,
ty: PhantomData<T>,
@ -39,6 +40,7 @@ impl<T: MetaValue> MetadataKey<T> {
}
}
#[derive(Clone, PartialEq)]
pub struct Metadata {
map: HashMap<i32, Value>,
}
@ -491,7 +493,7 @@ impl Default for Metadata {
}
}
#[derive(Debug)]
#[derive(Debug, Clone, PartialEq)]
pub enum Value {
Byte(i8),
Short(i16),
@ -516,7 +518,7 @@ pub enum Value {
Pose(PoseData),
}
#[derive(Debug)]
#[derive(Debug, Clone, PartialEq)]
pub enum ParticleData {
AmbientEntityEffect,
AngryVillager,
@ -655,7 +657,7 @@ impl Serializable for ParticleData {
}
}
#[derive(Debug)]
#[derive(Debug, Clone, PartialEq, Eq)]
#[allow(dead_code)]
pub struct VillagerData {
villager_type: protocol::VarInt,
@ -680,7 +682,7 @@ impl Serializable for VillagerData {
}
}
#[derive(Debug)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum PoseData {
Standing,
FallFlying,

View File

@ -19,7 +19,7 @@ pub mod bit;
pub mod hash;
pub mod nibble;
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Gamemode {
Survival = 0,
Creative = 1,

View File

@ -393,7 +393,7 @@ fn flood_fill(snapshot: &world::Snapshot, visited: &mut Set, x: i32, y: i32, z:
touched
}
#[derive(Clone, Copy, Default)]
#[derive(Clone, Copy, Default, PartialEq, Eq)]
pub struct CullInfo(u64);
impl CullInfo {