How to implement Serialize and Deserialize for bitwise flags?

I'm using the bitflags crate:

bitflags! {
    #[derive(Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
    pub struct FunctionFlags: u32 {
        const AWAIT     = 0b00000001;
        const YIELD     = 0b00000010;
    }
}

I get:

error[E0277]: the trait bound `ast::_::InternalBitFlags: Deserialize<'_>` is not satisfied
   --> crates\as3_parser\src\ast.rs:840:1
    |
840 | / bitflags! {
841 | |     #[derive(Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
842 | |     pub struct FunctionFlags: u32 {
843 | |         const AWAIT     = 0b00000001;
844 | |         const YIELD     = 0b00000010;
845 | |     }
846 | | }
    | |_^ the trait `Deserialize<'_>` is not implemented for `ast::_::InternalBitFlags`

I could just skip these flags as well in my case, but if I want full parser tests I am not sure...

Looking at bitflags I see you need to enable its serde feature.

1 Like