Lymia / enumset

A library for compact bit sets containing enums.
Apache License 2.0
91 stars 35 forks source link

Compatible with serde derive(Serialize, Deserialize) #14

Closed enebo closed 4 years ago

enebo commented 4 years ago

I made a struct along the lines of:

#[derive(EnumSetType, Serialize, Deserialize, Debug)]
enum ItemType { A, B, C }

#[derive(Serialize, Deserialize, Debug)]
struct Item {
  name: String,
  types: EnumSet<ItemType>
}

I get an error like this:

error[E0277]: the trait bound `enumset::EnumSet<ItemType>: _IMPL_DESERIALIZE_FOR_ItemType::_serde::Serialize` is not satisfied
   --> src\main.rs:250:5
    |
250 |     types: EnumSet<ItemType>,
    |     ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `_IMPL_DESERIALIZE_FOR_ItemType::_serde::Serialize` is not implemented for `enumset::EnumSet<ItemType>`

I am fairly new to Rust but should this work? I installed cargo-tree and there seems to be no version conflicts. Here is what my toml deps looks like:

[dependencies]
sxd-document = "0.3.2"
sxd-xpath = "0.4.2"
enumset = "1.0.0"
serde = { version = "1.0", features = ["derive"] }
enebo commented 4 years ago

Ok my problem was that I did not enable serde in enumset. The solution is:

enumset = { version = "1.0.0", features = ["serde"] }

This is probably obvious to an experienced rust dev but I missed the sole line:

For serde support, enable the serde feature.

Maybe add a config line like the one I wrote above to your docs? I don't know if this is something I just should have known or not.

I now have a new issue that I cannot write custom u128 but that is not this issue and I will poke around to see if I can figure that out.