Skip to content

fix! Remove ability to create heterogeneous lists - #51

Draft
Fisch37 wants to merge 3 commits into
CrabCraftDev:mainfrom
Fisch37:fix/homogenous-lists
Draft

fix! Remove ability to create heterogeneous lists#51
Fisch37 wants to merge 3 commits into
CrabCraftDev:mainfrom
Fisch37:fix/homogenous-lists

Conversation

@Fisch37

@Fisch37 Fisch37 commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

This is an implementation of the fix I have outlined in #46 (see this message) to address #45 namely the fact that we currently allow heterogeneous lists to be created (and serialize them), which is not standard NBT.

I will save us the time and not repeat my arguments for this implementation as you can find them in the message linked above.

There are still some features to reimplement for the new system and open questions remain. For this reason, this request is still in draft phase.

ToDos

  • NBT and SNBT serialization of lists
  • Include the End tag type in various APIs

Open Questions

Should TryAsRef and TryAsMut be unrolled into individual methods?

This PR includes two generic traits TryAsRef and TryAsMut, which are fallible versions of AsRef and AsMut, and provide the extraction methods for both NbtList and dyn NbtCompatible.

While they are very helpful, keeping them as part of the API requires exposing them to users, which could be considered problematic as they do not align with the rest of the project's goals.

How to handle empty lists?

Empty lists can try_as_ref and try_as_mut into any supported Vec type. If NbtList was previously holding an allocated list, this will drop that allocation, which could be considered undesirable. However it is very unusual for a mutable reference to not be unused, thus this issue is very rare and need not be addressed.

@Fisch37

Fisch37 commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

The trait(s) are actually not a required part of this PR, I realised. They help make some of the code neater, but all uses of them could be replaced by match-statements over NbtList.

Perhaps they would be better served as a separate PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant