gitoxide_core/
net.rs

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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use std::str::FromStr;

#[derive(Default, Clone, Eq, PartialEq, Debug)]
pub enum Protocol {
    V1,
    #[default]
    V2,
}

impl FromStr for Protocol {
    type Err = String;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(match s {
            "1" => Protocol::V1,
            "2" => Protocol::V2,
            _ => return Err(format!("Unsupported protocol version '{s}', choose '1' or '2'")),
        })
    }
}

#[cfg(any(feature = "blocking-client", feature = "async-client"))]
mod impls {
    use gix::protocol::transport;

    use super::Protocol;

    impl From<Protocol> for transport::Protocol {
        fn from(v: Protocol) -> Self {
            match v {
                Protocol::V1 => transport::Protocol::V1,
                Protocol::V2 => transport::Protocol::V2,
            }
        }
    }
}

#[cfg(any(feature = "async-client", feature = "blocking-client"))]
#[gix::protocol::maybe_async::maybe_async]
pub async fn connect<Url, E>(
    url: Url,
    options: gix::protocol::transport::client::connect::Options,
) -> Result<
    gix::protocol::SendFlushOnDrop<Box<dyn gix::protocol::transport::client::Transport + Send>>,
    gix::protocol::transport::client::connect::Error,
>
where
    Url: TryInto<gix::url::Url, Error = E>,
    gix::url::parse::Error: From<E>,
{
    Ok(gix::protocol::SendFlushOnDrop::new(
        gix::protocol::transport::connect(url, options).await?,
        false,
    ))
}