Closed RubixDev closed 2 years ago
I now also added a few things from the sNBT syntax like booleans mapping to 0 and 1 as bytes and the special array syntax for Byte/Int/Long Arrays. I do not allow identifiers as keys in compunds, only quoted strings, because one might want to use the value of a variable as a key
This looks awesome. I will have a closer look soon.
Merging this, thank you for your contribution! I'll have a deeper look and make a 2.1 release.
This adds a
nbt!
macro similar to thejson!
macro from serde_json. The code is actually mostly copied from there, but modified for NBT.An example usage might look like this:
I have taken the simple approach of turning expressions into
fastnbt::Value
s and implemented theFrom<T>
trait for a few types (all number types,String
,&str
,ByteArray
,IntArray
,LongArray
, and all their referenced versions). If you would like me to do it theserde_json
way and implement a Serializer withfastnbt::Value
as the target type, I can do that too. That would allow any type with theSerialize
trait to be turned into a value.I also added one simple test, but no documentation. You are free to do that in the way you like