slotmap icon indicating copy to clipboard operation
slotmap copied to clipboard

Serialization Issue with Unit Types in SlotMap<ID, ()>

Open maximsnoep opened this issue 7 months ago • 0 comments

First of all, thank you for maintaining the slotmap crate.

I'm currently using SlotMap with various generic types (VertData, FaceData, EdgeData) to manage graph data in my application:

SlotMap<VertID, VertData>
SlotMap<FaceID, FaceData>
SlotMap<EdgeID, EdgeData>

Occasionally, I use unit types for certain slot maps when no specific data needs to be stored (i.e., SlotMap<EdgeID, ()>). However, I've encountered serialization and deserialization issues when using unit types.

Issue

When attempting to serialize and deserialize a SlotMap<ID, ()>, it results in an error: "inconsistent occupation in Slot".

This seems to be triggered by the serialization behavior of the unit type (), which Serde serializes as "null" and then deserializes as None:

if occupied ^ serde_slot.value.is_some() {
    return Err(de::Error::custom("inconsistent occupation in Slot"));
}

Is this expected behavior?

maximsnoep avatar Jul 17 '24 17:07 maximsnoep