1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use {
    enumset::{
        EnumSet,
        EnumSetType,
        EnumSetTypeWithRepr,
    },
    async_proto_derive::impl_protocol_for,
    crate::Protocol,
};

#[derive(Protocol)]
#[async_proto(internal, where())]
struct EnumSetProxy<T: EnumSetType + EnumSetTypeWithRepr>(<T as EnumSetTypeWithRepr>::Repr)
where <T as EnumSetTypeWithRepr>::Repr: Protocol + Send + Sync;

impl<T: EnumSetType + EnumSetTypeWithRepr> From<EnumSetProxy<T>> for EnumSet<T>
where <T as EnumSetTypeWithRepr>::Repr: Protocol + Send + Sync {
    fn from(EnumSetProxy(repr): EnumSetProxy<T>) -> Self {
        Self::from_repr_truncated(repr)
    }
}

impl<'a, T: EnumSetType + EnumSetTypeWithRepr> From<&'a EnumSet<T>> for EnumSetProxy<T>
where <T as EnumSetTypeWithRepr>::Repr: Protocol + Send + Sync {
    fn from(set: &EnumSet<T>) -> Self {
        Self(set.as_repr())
    }
}

impl_protocol_for! {
    #[async_proto(attr(cfg_attr(docsrs, doc(cfg(feature = "enumset")))))]
    #[async_proto(attr(doc = "The type will be read via [`from_repr_truncated`](enumset::EnumSet::from_repr_truncated), ignoring invalid variants."))]
    #[async_proto(via = EnumSetProxy<T>, where())]
    type EnumSet<T: EnumSetType + EnumSetTypeWithRepr>
    where <T as EnumSetTypeWithRepr>::Repr: Protocol + Send + Sync;
}