async_proto/impls/
gix_hash.rs1use {
2 gix_hash::ObjectId,
3 async_proto_derive::impl_protocol_for,
4 crate::Protocol,
5};
6
7#[derive(Protocol)]
8#[async_proto(internal)]
9struct OidProxy([u8; 20]);
10
11impl From<OidProxy> for ObjectId {
12 fn from(OidProxy(sha1): OidProxy) -> Self {
13 Self::Sha1(sha1)
14 }
15}
16
17impl<'a> From<&'a ObjectId> for OidProxy {
18 fn from(oid: &ObjectId) -> Self {
19 match oid.kind() {
20 gix_hash::Kind::Sha1 => {
21 let ObjectId::Sha1(sha1) = *oid else { unreachable!("gix-hash kind mismatch") };
22 Self(sha1)
23 }
24 }
25 }
26}
27
28impl_protocol_for! {
29 #[async_proto(attr(cfg_attr(docsrs, doc(cfg(feature = "gix-hash")))))]
30 #[async_proto(via = OidProxy)]
31 type ObjectId;
32}