git2/
proxy_options.rs

1use std::ffi::CString;
2use std::marker;
3use std::ptr;
4
5use crate::raw;
6use crate::util::Binding;
7
8/// Options which can be specified to various fetch operations.
9#[derive(Default)]
10pub struct ProxyOptions<'a> {
11    url: Option<CString>,
12    proxy_kind: raw::git_proxy_t,
13    _marker: marker::PhantomData<&'a i32>,
14}
15
16impl<'a> ProxyOptions<'a> {
17    /// Creates a new set of proxy options ready to be configured.
18    pub fn new() -> ProxyOptions<'a> {
19        Default::default()
20    }
21
22    /// Try to auto-detect the proxy from the git configuration.
23    ///
24    /// Note that this will override `url` specified before.
25    pub fn auto(&mut self) -> &mut Self {
26        self.proxy_kind = raw::GIT_PROXY_AUTO;
27        self
28    }
29
30    /// Specify the exact URL of the proxy to use.
31    ///
32    /// Note that this will override `auto` specified before.
33    pub fn url(&mut self, url: &str) -> &mut Self {
34        self.proxy_kind = raw::GIT_PROXY_SPECIFIED;
35        self.url = Some(CString::new(url).unwrap());
36        self
37    }
38}
39
40impl<'a> Binding for ProxyOptions<'a> {
41    type Raw = raw::git_proxy_options;
42    unsafe fn from_raw(_raw: raw::git_proxy_options) -> ProxyOptions<'a> {
43        panic!("can't create proxy from raw options")
44    }
45
46    fn raw(&self) -> raw::git_proxy_options {
47        raw::git_proxy_options {
48            version: raw::GIT_PROXY_OPTIONS_VERSION,
49            kind: self.proxy_kind,
50            url: self.url.as_ref().map(|s| s.as_ptr()).unwrap_or(ptr::null()),
51            credentials: None,
52            certificate_check: None,
53            payload: ptr::null_mut(),
54        }
55    }
56}