Skip to content

Commit

Permalink
feat: Implement PartialOrd for nbt types
Browse files Browse the repository at this point in the history
  • Loading branch information
SzczurekYT committed Oct 7, 2024
1 parent 23ac624 commit b528476
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/nbt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub mod utils;

/// Represents the main NBT structure.
/// It contains the root compound tag of the NBT structure and its associated name
#[derive(Clone, PartialEq, Debug, Default)]
#[derive(Clone, Debug, Default, PartialEq, PartialOrd)]
pub struct Nbt {
pub name: String,
pub root_tag: NbtCompound,
Expand Down
12 changes: 6 additions & 6 deletions src/nbt/compound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ use bytes::{Buf, BufMut, Bytes, BytesMut};
use crab_nbt::nbt::tag::NbtTag;
use crab_nbt::nbt::utils::{get_nbt_string, END_ID};
use derive_more::Into;
use std::collections::{hash_map::IntoIter, HashMap};
use std::collections::{btree_map::IntoIter, BTreeMap};
use std::io::{Cursor, Write};

#[derive(Clone, PartialEq, Debug, Default, Into)]
#[derive(Clone, Debug, Default, PartialEq, PartialOrd, Into)]
pub struct NbtCompound {
pub child_tags: HashMap<String, NbtTag>,
pub child_tags: BTreeMap<String, NbtTag>,
}

impl NbtCompound {
pub fn new() -> NbtCompound {
NbtCompound {
child_tags: HashMap::new(),
child_tags: BTreeMap::new(),
}
}

pub fn deserialize_content(bytes: &mut impl Buf) -> Result<NbtCompound, Error> {
let mut child_tags = HashMap::new();
let mut child_tags = BTreeMap::new();

while bytes.has_remaining() {
let tag_id = bytes.get_u8();
Expand Down Expand Up @@ -137,7 +137,7 @@ impl From<Nbt> for NbtCompound {
impl FromIterator<(String, NbtTag)> for NbtCompound {
fn from_iter<T: IntoIterator<Item = (String, NbtTag)>>(iter: T) -> Self {
Self {
child_tags: HashMap::from_iter(iter),
child_tags: BTreeMap::from_iter(iter),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/nbt/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::io::Cursor;
/// Enum representing the different types of NBT tags.
/// Each variant corresponds to a different type of data that can be stored in an NBT tag.
#[repr(u8)]
#[derive(Clone, PartialEq, Debug, From)]
#[derive(Clone, Debug, PartialEq, PartialOrd, From)]
pub enum NbtTag {
End = END_ID,
Byte(i8) = BYTE_ID,
Expand Down

0 comments on commit b528476

Please sign in to comment.