async-proto 0.26.14

Simple async binary network protocols
Documentation
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.kind() {
            gix_hash::Kind::Sha1 => {
                let ObjectId::Sha1(sha1) = *oid else { unreachable!("gix-hash kind mismatch") };
                Self(sha1)
            }
            _ => unreachable!("enum marked as nonexhaustive"),
        }
    }
}

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