Skip to content

Commit

Permalink
fix: moooooore
Browse files Browse the repository at this point in the history
  • Loading branch information
SzczurekYT committed Apr 7, 2024
1 parent fd82073 commit 9c638f8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
11 changes: 0 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,6 @@ fn main() {
}
});

// The macro can also take variables to use data calculated at runtime
let var_as_key = "some_key".to_owned();
let other_key = "other_key".to_owned();
let value = vec![0, 1, 2];
let other_value = vec![3, 2, 1];
let nbt = nbt!("root", {
var_as_key: "wohoo!",
"the_other_way": value,
other_key: other_value,
});

let nbt = Nbt::new(
"root".to_owned(),
NbtCompound::from_iter([
Expand Down
10 changes: 7 additions & 3 deletions src/nbt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,13 @@ impl From<NbtCompound> for Nbt {
}
}

impl AsRef<NbtCompound> for Nbt {
fn as_ref(&self) -> &NbtCompound {
&self.root_tag
impl<T> AsRef<T> for Nbt
where
T: ?Sized,
<Nbt as Deref>::Target: AsRef<T>,
{
fn as_ref(&self) -> &T {
self.deref().as_ref()
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/nbt/compound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,10 @@ impl Extend<(String, NbtTag)> for NbtCompound {
self.child_tags.extend(iter)
}
}

// Rust's AsRef is currently not reflexive so we need to implement it manually
impl AsRef<NbtCompound> for NbtCompound {
fn as_ref(&self) -> &NbtCompound {
self
}
}

0 comments on commit 9c638f8

Please sign in to comment.