gitoxide_core/
net.rs

1use std::str::FromStr;
2
3#[derive(Default, Clone, Eq, PartialEq, Debug)]
4pub enum Protocol {
5    V1,
6    #[default]
7    V2,
8}
9
10impl FromStr for Protocol {
11    type Err = String;
12
13    fn from_str(s: &str) -> Result<Self, Self::Err> {
14        Ok(match s {
15            "1" => Protocol::V1,
16            "2" => Protocol::V2,
17            _ => return Err(format!("Unsupported protocol version '{s}', choose '1' or '2'")),
18        })
19    }
20}
21
22#[cfg(any(feature = "blocking-client", feature = "async-client"))]
23mod impls {
24    use gix::protocol::transport;
25
26    use super::Protocol;
27
28    impl From<Protocol> for transport::Protocol {
29        fn from(v: Protocol) -> Self {
30            match v {
31                Protocol::V1 => transport::Protocol::V1,
32                Protocol::V2 => transport::Protocol::V2,
33            }
34        }
35    }
36}
37
38#[cfg(any(feature = "async-client", feature = "blocking-client"))]
39#[gix::protocol::maybe_async::maybe_async]
40pub async fn connect<Url, E>(
41    url: Url,
42    options: gix::protocol::transport::client::connect::Options,
43) -> Result<
44    gix::protocol::SendFlushOnDrop<Box<dyn gix::protocol::transport::client::Transport + Send>>,
45    gix::protocol::transport::client::connect::Error,
46>
47where
48    Url: TryInto<gix::url::Url, Error = E>,
49    gix::url::parse::Error: From<E>,
50{
51    Ok(gix::protocol::SendFlushOnDrop::new(
52        gix::protocol::transport::connect(url, options).await?,
53        false,
54    ))
55}