Conversation
|
Hi, sorry for the long delay. I'm not entirely sure how to go about implementing this, I think it would have to be an entirely new value type to be backwards compatible. You're usage of features is not additive, which would potentially break the crate for others, see these cargo docs on feature unification. |
|
Thank you for your feedback! I agree with your concerns about backward compatibility and the additive principle. If we were to introduce an additional type called At that time, the code would feature definitions like this: #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum OrderedValue {
Byte(i8),
Short(i16),
Int(i32),
Long(i64),
Float(f32),
Double(f64),
String(String),
ByteArray(ByteArray),
IntArray(IntArray),
LongArray(LongArray),
List(Vec<OrderedValue>),
Compound(BTreeMap<String, OrderedValue>), // NOTE: BTreeMap here
} |
This PR introduces a new
btreemapfeature. When this feature is enabled, theHashMapinfastnbt::Value::Compoundwill be replaced with aBTreeMap. This feature is disabled by default, so it is expected not to conflict with any existing code.Motivation
In certain scenarios, I need to ensure that the serialization result of
Valueis consistent. Here is an example:In the previous implementation, since
HashMapdoes not guarantee iteration order, the serialization result of the sameValuemight be different. That is, in the above test, the assertionx == zpasses, but the assertiony == wfails.I tried to use a custom
Valuetype to solve this problem, but it resulted in an errorError: Error("invalid nbt: no root compound")(see #124).Todo list
The following tasks may still need to be completed for this PR:
Although I can complete the above tasks myself, I would still like to get feedback from the project maintainers before proceeding, in order to avoid unnecessary work.