    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

    //! Utilities for networking.

    use std::task::Poll;

    pub mod proxy;
    pub mod retry;
    pub mod sleep;

    pub trait PollExt<T> {
        fn expect(self, msg: &str) -> T;
    }

    impl<T> PollExt<T> for Poll<T> {
        #[track_caller]
        fn expect(self, msg: &str) -> T {
            match self {
                Poll::Ready(val) => val,
                Poll::Pending => panic!("{}", msg),
            }
        }
    }

    // When dynamically linked against libcurl, we want to ignore some failures
    // when using old versions that don't support certain features.
    #[macro_export]
    macro_rules! try_old_curl {
        ($e:expr, $msg:expr) => {
            let result = $e;
            if cfg!(target_os = "macos") {
                if let Err(e) = result {
                    warn!("ignoring libcurl {} error: {}", $msg, e);
                }
            } else {
                result.with_context(|| {
                    anyhow::format_err!("failed to enable {}, is curl not built right?", $msg)
                })?;
            }
        };
    }