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
use {
    gix_hash::ObjectId,
    async_proto_derive::impl_protocol_for,
    crate::Protocol,
};

#[derive(Protocol)]
#[async_proto(internal)]
struct OidProxy([u8; 20]);

impl From<OidProxy> for ObjectId {
    fn from(OidProxy(sha1): OidProxy) -> Self {
        Self::Sha1(sha1)
    }
}

impl<'a> From<&'a ObjectId> for OidProxy {
    fn from(oid: &ObjectId) -> Self {
        match *oid {
            ObjectId::Sha1(sha1) => Self(sha1),
        }
    }
}

impl_protocol_for! {
    #[async_proto(attr(cfg_attr(docsrs, doc(cfg(feature = "gix-hash")))))]
    #[async_proto(via = OidProxy)]
    type ObjectId;
}