async_proto/impls/
enumset.rs1use {
2 enumset::{
3 EnumSet,
4 EnumSetType,
5 EnumSetTypeWithRepr,
6 },
7 async_proto_derive::impl_protocol_for,
8 crate::Protocol,
9};
10
11#[derive(Protocol)]
12#[async_proto(internal, where())]
13struct EnumSetProxy<T: EnumSetType + EnumSetTypeWithRepr>(<T as EnumSetTypeWithRepr>::Repr)
14where <T as EnumSetTypeWithRepr>::Repr: Protocol + Send + Sync;
15
16impl<T: EnumSetType + EnumSetTypeWithRepr> From<EnumSetProxy<T>> for EnumSet<T>
17where <T as EnumSetTypeWithRepr>::Repr: Protocol + Send + Sync {
18 fn from(EnumSetProxy(repr): EnumSetProxy<T>) -> Self {
19 Self::from_repr_truncated(repr)
20 }
21}
22
23impl<'a, T: EnumSetType + EnumSetTypeWithRepr> From<&'a EnumSet<T>> for EnumSetProxy<T>
24where <T as EnumSetTypeWithRepr>::Repr: Protocol + Send + Sync {
25 fn from(set: &EnumSet<T>) -> Self {
26 Self(set.as_repr())
27 }
28}
29
30impl_protocol_for! {
31 #[async_proto(attr(cfg_attr(docsrs, doc(cfg(feature = "enumset")))))]
32 #[async_proto(attr(doc = "The type will be read via [`from_repr_truncated`](enumset::EnumSet::from_repr_truncated), ignoring invalid variants."))]
33 #[async_proto(via = EnumSetProxy<T>, where())]
34 type EnumSet<T: EnumSetType + EnumSetTypeWithRepr>
35 where <T as EnumSetTypeWithRepr>::Repr: Protocol + Send + Sync;
36}