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::InetAddress; 6 use crate::Initable; 7 use crate::SocketFamily; 8 use glib::object::Cast; 9 use glib::object::IsA; 10 use glib::signal::connect_raw; 11 use glib::signal::SignalHandlerId; 12 use glib::translate::*; 13 use glib::ToValue; 14 use std::boxed::Box as Box_; 15 use std::fmt; 16 use std::mem::transmute; 17 use std::ptr; 18 19 glib::wrapper! { 20 #[doc(alias = "GInetAddressMask")] 21 pub struct InetAddressMask(Object<ffi::GInetAddressMask, ffi::GInetAddressMaskClass>) @implements Initable; 22 23 match fn { 24 type_ => || ffi::g_inet_address_mask_get_type(), 25 } 26 } 27 28 impl InetAddressMask { 29 #[doc(alias = "g_inet_address_mask_new")] new<P: IsA<InetAddress>>(addr: &P, length: u32) -> Result<InetAddressMask, glib::Error>30 pub fn new<P: IsA<InetAddress>>(addr: &P, length: u32) -> Result<InetAddressMask, glib::Error> { 31 unsafe { 32 let mut error = ptr::null_mut(); 33 let ret = 34 ffi::g_inet_address_mask_new(addr.as_ref().to_glib_none().0, length, &mut error); 35 if error.is_null() { 36 Ok(from_glib_full(ret)) 37 } else { 38 Err(from_glib_full(error)) 39 } 40 } 41 } 42 43 #[doc(alias = "g_inet_address_mask_new_from_string")] 44 #[doc(alias = "new_from_string")] from_string(mask_string: &str) -> Result<InetAddressMask, glib::Error>45 pub fn from_string(mask_string: &str) -> Result<InetAddressMask, glib::Error> { 46 unsafe { 47 let mut error = ptr::null_mut(); 48 let ret = 49 ffi::g_inet_address_mask_new_from_string(mask_string.to_glib_none().0, &mut error); 50 if error.is_null() { 51 Ok(from_glib_full(ret)) 52 } else { 53 Err(from_glib_full(error)) 54 } 55 } 56 } 57 } 58 59 impl fmt::Display for InetAddressMask { 60 #[inline] fmt(&self, f: &mut fmt::Formatter) -> fmt::Result61 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 62 f.write_str(&InetAddressMaskExt::to_str(self)) 63 } 64 } 65 66 unsafe impl Send for InetAddressMask {} 67 unsafe impl Sync for InetAddressMask {} 68 69 pub const NONE_INET_ADDRESS_MASK: Option<&InetAddressMask> = None; 70 71 pub trait InetAddressMaskExt: 'static { 72 #[doc(alias = "g_inet_address_mask_equal")] equal<P: IsA<InetAddressMask>>(&self, mask2: &P) -> bool73 fn equal<P: IsA<InetAddressMask>>(&self, mask2: &P) -> bool; 74 75 #[doc(alias = "g_inet_address_mask_get_address")] 76 #[doc(alias = "get_address")] address(&self) -> InetAddress77 fn address(&self) -> InetAddress; 78 79 #[doc(alias = "g_inet_address_mask_get_family")] 80 #[doc(alias = "get_family")] family(&self) -> SocketFamily81 fn family(&self) -> SocketFamily; 82 83 #[doc(alias = "g_inet_address_mask_get_length")] 84 #[doc(alias = "get_length")] length(&self) -> u3285 fn length(&self) -> u32; 86 87 #[doc(alias = "g_inet_address_mask_matches")] matches<P: IsA<InetAddress>>(&self, address: &P) -> bool88 fn matches<P: IsA<InetAddress>>(&self, address: &P) -> bool; 89 90 #[doc(alias = "g_inet_address_mask_to_string")] 91 #[doc(alias = "to_string")] to_str(&self) -> glib::GString92 fn to_str(&self) -> glib::GString; 93 set_address<P: IsA<InetAddress>>(&self, address: Option<&P>)94 fn set_address<P: IsA<InetAddress>>(&self, address: Option<&P>); 95 set_length(&self, length: u32)96 fn set_length(&self, length: u32); 97 98 #[doc(alias = "address")] connect_address_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId99 fn connect_address_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) 100 -> SignalHandlerId; 101 102 #[doc(alias = "family")] connect_family_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId103 fn connect_family_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId; 104 105 #[doc(alias = "length")] connect_length_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId106 fn connect_length_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId; 107 } 108 109 impl<O: IsA<InetAddressMask>> InetAddressMaskExt for O { equal<P: IsA<InetAddressMask>>(&self, mask2: &P) -> bool110 fn equal<P: IsA<InetAddressMask>>(&self, mask2: &P) -> bool { 111 unsafe { 112 from_glib(ffi::g_inet_address_mask_equal( 113 self.as_ref().to_glib_none().0, 114 mask2.as_ref().to_glib_none().0, 115 )) 116 } 117 } 118 address(&self) -> InetAddress119 fn address(&self) -> InetAddress { 120 unsafe { 121 from_glib_none(ffi::g_inet_address_mask_get_address( 122 self.as_ref().to_glib_none().0, 123 )) 124 } 125 } 126 family(&self) -> SocketFamily127 fn family(&self) -> SocketFamily { 128 unsafe { 129 from_glib(ffi::g_inet_address_mask_get_family( 130 self.as_ref().to_glib_none().0, 131 )) 132 } 133 } 134 length(&self) -> u32135 fn length(&self) -> u32 { 136 unsafe { ffi::g_inet_address_mask_get_length(self.as_ref().to_glib_none().0) } 137 } 138 matches<P: IsA<InetAddress>>(&self, address: &P) -> bool139 fn matches<P: IsA<InetAddress>>(&self, address: &P) -> bool { 140 unsafe { 141 from_glib(ffi::g_inet_address_mask_matches( 142 self.as_ref().to_glib_none().0, 143 address.as_ref().to_glib_none().0, 144 )) 145 } 146 } 147 to_str(&self) -> glib::GString148 fn to_str(&self) -> glib::GString { 149 unsafe { 150 from_glib_full(ffi::g_inet_address_mask_to_string( 151 self.as_ref().to_glib_none().0, 152 )) 153 } 154 } 155 set_address<P: IsA<InetAddress>>(&self, address: Option<&P>)156 fn set_address<P: IsA<InetAddress>>(&self, address: Option<&P>) { 157 unsafe { 158 glib::gobject_ffi::g_object_set_property( 159 self.to_glib_none().0 as *mut glib::gobject_ffi::GObject, 160 b"address\0".as_ptr() as *const _, 161 address.to_value().to_glib_none().0, 162 ); 163 } 164 } 165 set_length(&self, length: u32)166 fn set_length(&self, length: u32) { 167 unsafe { 168 glib::gobject_ffi::g_object_set_property( 169 self.to_glib_none().0 as *mut glib::gobject_ffi::GObject, 170 b"length\0".as_ptr() as *const _, 171 length.to_value().to_glib_none().0, 172 ); 173 } 174 } 175 connect_address_notify<F: Fn(&Self) + Send + Sync + 'static>( &self, f: F, ) -> SignalHandlerId176 fn connect_address_notify<F: Fn(&Self) + Send + Sync + 'static>( 177 &self, 178 f: F, 179 ) -> SignalHandlerId { 180 unsafe extern "C" fn notify_address_trampoline< 181 P: IsA<InetAddressMask>, 182 F: Fn(&P) + Send + Sync + 'static, 183 >( 184 this: *mut ffi::GInetAddressMask, 185 _param_spec: glib::ffi::gpointer, 186 f: glib::ffi::gpointer, 187 ) { 188 let f: &F = &*(f as *const F); 189 f(InetAddressMask::from_glib_borrow(this).unsafe_cast_ref()) 190 } 191 unsafe { 192 let f: Box_<F> = Box_::new(f); 193 connect_raw( 194 self.as_ptr() as *mut _, 195 b"notify::address\0".as_ptr() as *const _, 196 Some(transmute::<_, unsafe extern "C" fn()>( 197 notify_address_trampoline::<Self, F> as *const (), 198 )), 199 Box_::into_raw(f), 200 ) 201 } 202 } 203 connect_family_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId204 fn connect_family_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId { 205 unsafe extern "C" fn notify_family_trampoline< 206 P: IsA<InetAddressMask>, 207 F: Fn(&P) + Send + Sync + 'static, 208 >( 209 this: *mut ffi::GInetAddressMask, 210 _param_spec: glib::ffi::gpointer, 211 f: glib::ffi::gpointer, 212 ) { 213 let f: &F = &*(f as *const F); 214 f(InetAddressMask::from_glib_borrow(this).unsafe_cast_ref()) 215 } 216 unsafe { 217 let f: Box_<F> = Box_::new(f); 218 connect_raw( 219 self.as_ptr() as *mut _, 220 b"notify::family\0".as_ptr() as *const _, 221 Some(transmute::<_, unsafe extern "C" fn()>( 222 notify_family_trampoline::<Self, F> as *const (), 223 )), 224 Box_::into_raw(f), 225 ) 226 } 227 } 228 connect_length_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId229 fn connect_length_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId { 230 unsafe extern "C" fn notify_length_trampoline< 231 P: IsA<InetAddressMask>, 232 F: Fn(&P) + Send + Sync + 'static, 233 >( 234 this: *mut ffi::GInetAddressMask, 235 _param_spec: glib::ffi::gpointer, 236 f: glib::ffi::gpointer, 237 ) { 238 let f: &F = &*(f as *const F); 239 f(InetAddressMask::from_glib_borrow(this).unsafe_cast_ref()) 240 } 241 unsafe { 242 let f: Box_<F> = Box_::new(f); 243 connect_raw( 244 self.as_ptr() as *mut _, 245 b"notify::length\0".as_ptr() as *const _, 246 Some(transmute::<_, unsafe extern "C" fn()>( 247 notify_length_trampoline::<Self, F> as *const (), 248 )), 249 Box_::into_raw(f), 250 ) 251 } 252 } 253 } 254