1 // This file was generated by gir (https://github.com/gtk-rs/gir) 2 // from gir-files (https://github.com/gtk-rs/gir-files) 3 // DO NOT EDIT 4 5 use crate::AsyncResult; 6 use crate::Cancellable; 7 use crate::IOStream; 8 use crate::ProxyAddress; 9 use glib::object::IsA; 10 use glib::translate::*; 11 use std::boxed::Box as Box_; 12 use std::fmt; 13 use std::pin::Pin; 14 use std::ptr; 15 16 glib::wrapper! { 17 #[doc(alias = "GProxy")] 18 pub struct Proxy(Interface<ffi::GProxy, ffi::GProxyInterface>); 19 20 match fn { 21 type_ => || ffi::g_proxy_get_type(), 22 } 23 } 24 25 impl Proxy { 26 #[doc(alias = "g_proxy_get_default_for_protocol")] 27 #[doc(alias = "get_default_for_protocol")] default_for_protocol(protocol: &str) -> Option<Proxy>28 pub fn default_for_protocol(protocol: &str) -> Option<Proxy> { 29 unsafe { 30 from_glib_full(ffi::g_proxy_get_default_for_protocol( 31 protocol.to_glib_none().0, 32 )) 33 } 34 } 35 } 36 37 pub const NONE_PROXY: Option<&Proxy> = None; 38 39 pub trait ProxyExt: 'static { 40 #[doc(alias = "g_proxy_connect")] connect<P: IsA<IOStream>, Q: IsA<ProxyAddress>, R: IsA<Cancellable>>( &self, connection: &P, proxy_address: &Q, cancellable: Option<&R>, ) -> Result<IOStream, glib::Error>41 fn connect<P: IsA<IOStream>, Q: IsA<ProxyAddress>, R: IsA<Cancellable>>( 42 &self, 43 connection: &P, 44 proxy_address: &Q, 45 cancellable: Option<&R>, 46 ) -> Result<IOStream, glib::Error>; 47 48 #[doc(alias = "g_proxy_connect_async")] connect_async< P: IsA<IOStream>, Q: IsA<ProxyAddress>, R: IsA<Cancellable>, S: FnOnce(Result<IOStream, glib::Error>) + Send + 'static, >( &self, connection: &P, proxy_address: &Q, cancellable: Option<&R>, callback: S, )49 fn connect_async< 50 P: IsA<IOStream>, 51 Q: IsA<ProxyAddress>, 52 R: IsA<Cancellable>, 53 S: FnOnce(Result<IOStream, glib::Error>) + Send + 'static, 54 >( 55 &self, 56 connection: &P, 57 proxy_address: &Q, 58 cancellable: Option<&R>, 59 callback: S, 60 ); 61 connect_async_future< P: IsA<IOStream> + Clone + 'static, Q: IsA<ProxyAddress> + Clone + 'static, >( &self, connection: &P, proxy_address: &Q, ) -> Pin<Box_<dyn std::future::Future<Output = Result<IOStream, glib::Error>> + 'static>>62 fn connect_async_future< 63 P: IsA<IOStream> + Clone + 'static, 64 Q: IsA<ProxyAddress> + Clone + 'static, 65 >( 66 &self, 67 connection: &P, 68 proxy_address: &Q, 69 ) -> Pin<Box_<dyn std::future::Future<Output = Result<IOStream, glib::Error>> + 'static>>; 70 71 #[doc(alias = "g_proxy_supports_hostname")] supports_hostname(&self) -> bool72 fn supports_hostname(&self) -> bool; 73 } 74 75 impl<O: IsA<Proxy>> ProxyExt for O { connect<P: IsA<IOStream>, Q: IsA<ProxyAddress>, R: IsA<Cancellable>>( &self, connection: &P, proxy_address: &Q, cancellable: Option<&R>, ) -> Result<IOStream, glib::Error>76 fn connect<P: IsA<IOStream>, Q: IsA<ProxyAddress>, R: IsA<Cancellable>>( 77 &self, 78 connection: &P, 79 proxy_address: &Q, 80 cancellable: Option<&R>, 81 ) -> Result<IOStream, glib::Error> { 82 unsafe { 83 let mut error = ptr::null_mut(); 84 let ret = ffi::g_proxy_connect( 85 self.as_ref().to_glib_none().0, 86 connection.as_ref().to_glib_none().0, 87 proxy_address.as_ref().to_glib_none().0, 88 cancellable.map(|p| p.as_ref()).to_glib_none().0, 89 &mut error, 90 ); 91 if error.is_null() { 92 Ok(from_glib_full(ret)) 93 } else { 94 Err(from_glib_full(error)) 95 } 96 } 97 } 98 connect_async< P: IsA<IOStream>, Q: IsA<ProxyAddress>, R: IsA<Cancellable>, S: FnOnce(Result<IOStream, glib::Error>) + Send + 'static, >( &self, connection: &P, proxy_address: &Q, cancellable: Option<&R>, callback: S, )99 fn connect_async< 100 P: IsA<IOStream>, 101 Q: IsA<ProxyAddress>, 102 R: IsA<Cancellable>, 103 S: FnOnce(Result<IOStream, glib::Error>) + Send + 'static, 104 >( 105 &self, 106 connection: &P, 107 proxy_address: &Q, 108 cancellable: Option<&R>, 109 callback: S, 110 ) { 111 let user_data: Box_<S> = Box_::new(callback); 112 unsafe extern "C" fn connect_async_trampoline< 113 S: FnOnce(Result<IOStream, glib::Error>) + Send + 'static, 114 >( 115 _source_object: *mut glib::gobject_ffi::GObject, 116 res: *mut crate::ffi::GAsyncResult, 117 user_data: glib::ffi::gpointer, 118 ) { 119 let mut error = ptr::null_mut(); 120 let ret = ffi::g_proxy_connect_finish(_source_object as *mut _, res, &mut error); 121 let result = if error.is_null() { 122 Ok(from_glib_full(ret)) 123 } else { 124 Err(from_glib_full(error)) 125 }; 126 let callback: Box_<S> = Box_::from_raw(user_data as *mut _); 127 callback(result); 128 } 129 let callback = connect_async_trampoline::<S>; 130 unsafe { 131 ffi::g_proxy_connect_async( 132 self.as_ref().to_glib_none().0, 133 connection.as_ref().to_glib_none().0, 134 proxy_address.as_ref().to_glib_none().0, 135 cancellable.map(|p| p.as_ref()).to_glib_none().0, 136 Some(callback), 137 Box_::into_raw(user_data) as *mut _, 138 ); 139 } 140 } 141 connect_async_future< P: IsA<IOStream> + Clone + 'static, Q: IsA<ProxyAddress> + Clone + 'static, >( &self, connection: &P, proxy_address: &Q, ) -> Pin<Box_<dyn std::future::Future<Output = Result<IOStream, glib::Error>> + 'static>>142 fn connect_async_future< 143 P: IsA<IOStream> + Clone + 'static, 144 Q: IsA<ProxyAddress> + Clone + 'static, 145 >( 146 &self, 147 connection: &P, 148 proxy_address: &Q, 149 ) -> Pin<Box_<dyn std::future::Future<Output = Result<IOStream, glib::Error>> + 'static>> { 150 let connection = connection.clone(); 151 let proxy_address = proxy_address.clone(); 152 Box_::pin(crate::GioFuture::new( 153 self, 154 move |obj, cancellable, send| { 155 obj.connect_async(&connection, &proxy_address, Some(cancellable), move |res| { 156 send.resolve(res); 157 }); 158 }, 159 )) 160 } 161 supports_hostname(&self) -> bool162 fn supports_hostname(&self) -> bool { 163 unsafe { 164 from_glib(ffi::g_proxy_supports_hostname( 165 self.as_ref().to_glib_none().0, 166 )) 167 } 168 } 169 } 170 171 impl fmt::Display for Proxy { fmt(&self, f: &mut fmt::Formatter) -> fmt::Result172 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 173 f.write_str("Proxy") 174 } 175 } 176