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
56
use std::ffi::CString;
use std::marker;
use std::ptr;
use crate::raw;
use crate::util::Binding;
#[derive(Default)]
pub struct ProxyOptions<'a> {
url: Option<CString>,
proxy_kind: raw::git_proxy_t,
_marker: marker::PhantomData<&'a i32>,
}
impl<'a> ProxyOptions<'a> {
pub fn new() -> ProxyOptions<'a> {
Default::default()
}
pub fn auto(&mut self) -> &mut Self {
self.proxy_kind = raw::GIT_PROXY_AUTO;
self
}
pub fn url(&mut self, url: &str) -> &mut Self {
self.proxy_kind = raw::GIT_PROXY_SPECIFIED;
self.url = Some(CString::new(url).unwrap());
self
}
}
impl<'a> Binding for ProxyOptions<'a> {
type Raw = raw::git_proxy_options;
unsafe fn from_raw(_raw: raw::git_proxy_options) -> ProxyOptions<'a> {
panic!("can't create proxy from raw options")
}
fn raw(&self) -> raw::git_proxy_options {
raw::git_proxy_options {
version: raw::GIT_PROXY_OPTIONS_VERSION,
kind: self.proxy_kind,
url: self.url.as_ref().map(|s| s.as_ptr()).unwrap_or(ptr::null()),
credentials: None,
certificate_check: None,
payload: ptr::null_mut(),
}
}
}