contain-rs / bit-set

A Set of Bits

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add support for serialization/deserialization

lzybkr opened this issue · comments

It would be useful if bit_set::BitSet supported serialization for serde. Today, if I add a BitSet to my struct, I get the following compiler errors because codegen can't automatically generate serialization for BitSet:

error[E0277]: the trait bound `bit_set::BitSet: serde::Serialize` is not satisfied
  --> src\coverage.rs:20:10
   |
20 | #[derive(Serialize, Deserialize)]
   |          ^^^^^^^^^ the trait `serde::Serialize` is not implemented for `bit_set::BitSet`
   |
   = note: required by `serde::ser::SerializeStruct::serialize_field`

error[E0277]: the trait bound `bit_set::BitSet: serde::Deserialize` is not satisfied
  --> src\coverage.rs:20:21
   |
20 | #[derive(Serialize, Deserialize)]
   |                     ^^^^^^^^^^^ the trait `serde::Deserialize` is not implemented for `bit_set::BitSet`
   |
   = note: required by `serde::de::SeqVisitor::visit`

error[E0277]: the trait bound `bit_set::BitSet: serde::Deserialize` is not satisfied
  --> src\coverage.rs:20:21
   |
20 | #[derive(Serialize, Deserialize)]
   |                     ^^^^^^^^^^^ the trait `serde::Deserialize` is not implemented for `bit_set::BitSet`
   |
   = note: required by `serde::de::MapVisitor::visit_value`

error[E0277]: the trait bound `bit_set::BitSet: serde::Deserialize` is not satisfied
  --> src\coverage.rs:20:21
   |
20 | #[derive(Serialize, Deserialize)]
   |                     ^^^^^^^^^^^ the trait `serde::Deserialize` is not implemented for `bit_set::BitSet`
   |
   = note: required by `serde::de::private::missing_field`

I would be interested in this as well. However, it is not as simple as just adding #[derive(Serialize, Deserialize)], since BitSet uses a bit vector implementation that itself is also not serializable.

Also modifying BitVec would make this work. I will implement some tests and write a pull request for that.

I created a branch that introduces serialization support (see here). I will create a PR once the PR for BitVec went through, since the changes there are required to make serialization for BitSet work.

@HenningTimm Thanks. I'll make sure the changes go through.

Edit: currently bit-set and bit-vec are in feature freeze mode, unfortunately.

The required changes to bit-vec are now there.