gio/
simple_proxy_resolver.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use glib::{prelude::*, translate::*};
4
5use crate::{ffi, ProxyResolver, SimpleProxyResolver};
6
7impl SimpleProxyResolver {
8    /// Creates a new #GSimpleProxyResolver. See
9    /// #GSimpleProxyResolver:default-proxy and
10    /// #GSimpleProxyResolver:ignore-hosts for more details on how the
11    /// arguments are interpreted.
12    /// ## `default_proxy`
13    /// the default proxy to use, eg
14    ///     "socks://192.168.1.1"
15    /// ## `ignore_hosts`
16    /// an optional list of hosts/IP addresses
17    ///     to not use a proxy for.
18    ///
19    /// # Returns
20    ///
21    /// a new #GSimpleProxyResolver
22    #[doc(alias = "g_simple_proxy_resolver_new")]
23    #[allow(clippy::new_ret_no_self)]
24    pub fn new(default_proxy: Option<&str>, ignore_hosts: impl IntoStrV) -> ProxyResolver {
25        unsafe {
26            ignore_hosts.run_with_strv(|ignore_hosts| {
27                from_glib_full(ffi::g_simple_proxy_resolver_new(
28                    default_proxy.to_glib_none().0,
29                    ignore_hosts.as_ptr() as *mut _,
30                ))
31            })
32        }
33    }
34}
35
36mod sealed {
37    pub trait Sealed {}
38    impl<T: super::IsA<super::SimpleProxyResolver>> Sealed for T {}
39}
40
41pub trait SimpleProxyResolverExtManual:
42    sealed::Sealed + IsA<SimpleProxyResolver> + 'static
43{
44    /// Sets the list of ignored hosts.
45    ///
46    /// See #GSimpleProxyResolver:ignore-hosts for more details on how the
47    /// @ignore_hosts argument is interpreted.
48    /// ## `ignore_hosts`
49    /// [`None`]-terminated list of hosts/IP addresses
50    ///     to not use a proxy for
51    #[doc(alias = "g_simple_proxy_resolver_set_ignore_hosts")]
52    fn set_ignore_hosts(&self, ignore_hosts: impl IntoStrV) {
53        unsafe {
54            ignore_hosts.run_with_strv(|ignore_hosts| {
55                ffi::g_simple_proxy_resolver_set_ignore_hosts(
56                    self.as_ref().to_glib_none().0,
57                    ignore_hosts.as_ptr() as *mut _,
58                );
59            })
60        }
61    }
62}
63
64impl<O: IsA<SimpleProxyResolver>> SimpleProxyResolverExtManual for O {}