gio/auto/
inet_address_mask.rs1use crate::{InetAddress, Initable, SocketFamily, ffi};
6use glib::{
7 prelude::*,
8 signal::{SignalHandlerId, connect_raw},
9 translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14 #[doc(alias = "GInetAddressMask")]
43 pub struct InetAddressMask(Object<ffi::GInetAddressMask, ffi::GInetAddressMaskClass>) @implements Initable;
44
45 match fn {
46 type_ => || ffi::g_inet_address_mask_get_type(),
47 }
48}
49
50impl InetAddressMask {
51 pub const NONE: Option<&'static InetAddressMask> = None;
52
53 #[doc(alias = "g_inet_address_mask_new")]
64 pub fn new(addr: &impl IsA<InetAddress>, length: u32) -> Result<InetAddressMask, glib::Error> {
65 unsafe {
66 let mut error = std::ptr::null_mut();
67 let ret =
68 ffi::g_inet_address_mask_new(addr.as_ref().to_glib_none().0, length, &mut error);
69 if error.is_null() {
70 Ok(from_glib_full(ret))
71 } else {
72 Err(from_glib_full(error))
73 }
74 }
75 }
76
77 #[doc(alias = "g_inet_address_mask_new_from_string")]
89 #[doc(alias = "new_from_string")]
90 pub fn from_string(mask_string: &str) -> Result<InetAddressMask, glib::Error> {
91 unsafe {
92 let mut error = std::ptr::null_mut();
93 let ret =
94 ffi::g_inet_address_mask_new_from_string(mask_string.to_glib_none().0, &mut error);
95 if error.is_null() {
96 Ok(from_glib_full(ret))
97 } else {
98 Err(from_glib_full(error))
99 }
100 }
101 }
102}
103
104impl std::fmt::Display for InetAddressMask {
105 #[inline]
106 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
107 f.write_str(&InetAddressMaskExt::to_str(self))
108 }
109}
110
111unsafe impl Send for InetAddressMask {}
112unsafe impl Sync for InetAddressMask {}
113
114pub trait InetAddressMaskExt: IsA<InetAddressMask> + 'static {
120 #[doc(alias = "g_inet_address_mask_equal")]
121 fn equal(&self, mask2: &impl IsA<InetAddressMask>) -> bool {
122 unsafe {
123 from_glib(ffi::g_inet_address_mask_equal(
124 self.as_ref().to_glib_none().0,
125 mask2.as_ref().to_glib_none().0,
126 ))
127 }
128 }
129
130 #[doc(alias = "g_inet_address_mask_get_address")]
136 #[doc(alias = "get_address")]
137 fn address(&self) -> InetAddress {
138 unsafe {
139 from_glib_none(ffi::g_inet_address_mask_get_address(
140 self.as_ref().to_glib_none().0,
141 ))
142 }
143 }
144
145 #[doc(alias = "g_inet_address_mask_get_family")]
151 #[doc(alias = "get_family")]
152 fn family(&self) -> SocketFamily {
153 unsafe {
154 from_glib(ffi::g_inet_address_mask_get_family(
155 self.as_ref().to_glib_none().0,
156 ))
157 }
158 }
159
160 #[doc(alias = "g_inet_address_mask_get_length")]
166 #[doc(alias = "get_length")]
167 fn length(&self) -> u32 {
168 unsafe { ffi::g_inet_address_mask_get_length(self.as_ref().to_glib_none().0) }
169 }
170
171 #[doc(alias = "g_inet_address_mask_matches")]
180 fn matches(&self, address: &impl IsA<InetAddress>) -> bool {
181 unsafe {
182 from_glib(ffi::g_inet_address_mask_matches(
183 self.as_ref().to_glib_none().0,
184 address.as_ref().to_glib_none().0,
185 ))
186 }
187 }
188
189 #[doc(alias = "g_inet_address_mask_to_string")]
195 #[doc(alias = "to_string")]
196 fn to_str(&self) -> glib::GString {
197 unsafe {
198 from_glib_full(ffi::g_inet_address_mask_to_string(
199 self.as_ref().to_glib_none().0,
200 ))
201 }
202 }
203
204 fn set_address<P: IsA<InetAddress>>(&self, address: Option<&P>) {
206 ObjectExt::set_property(self.as_ref(), "address", address)
207 }
208
209 fn set_length(&self, length: u32) {
211 ObjectExt::set_property(self.as_ref(), "length", length)
212 }
213
214 #[doc(alias = "address")]
215 fn connect_address_notify<F: Fn(&Self) + Send + Sync + 'static>(
216 &self,
217 f: F,
218 ) -> SignalHandlerId {
219 unsafe extern "C" fn notify_address_trampoline<
220 P: IsA<InetAddressMask>,
221 F: Fn(&P) + Send + Sync + 'static,
222 >(
223 this: *mut ffi::GInetAddressMask,
224 _param_spec: glib::ffi::gpointer,
225 f: glib::ffi::gpointer,
226 ) {
227 unsafe {
228 let f: &F = &*(f as *const F);
229 f(InetAddressMask::from_glib_borrow(this).unsafe_cast_ref())
230 }
231 }
232 unsafe {
233 let f: Box_<F> = Box_::new(f);
234 connect_raw(
235 self.as_ptr() as *mut _,
236 c"notify::address".as_ptr() as *const _,
237 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
238 notify_address_trampoline::<Self, F> as *const (),
239 )),
240 Box_::into_raw(f),
241 )
242 }
243 }
244
245 #[doc(alias = "family")]
246 fn connect_family_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
247 unsafe extern "C" fn notify_family_trampoline<
248 P: IsA<InetAddressMask>,
249 F: Fn(&P) + Send + Sync + 'static,
250 >(
251 this: *mut ffi::GInetAddressMask,
252 _param_spec: glib::ffi::gpointer,
253 f: glib::ffi::gpointer,
254 ) {
255 unsafe {
256 let f: &F = &*(f as *const F);
257 f(InetAddressMask::from_glib_borrow(this).unsafe_cast_ref())
258 }
259 }
260 unsafe {
261 let f: Box_<F> = Box_::new(f);
262 connect_raw(
263 self.as_ptr() as *mut _,
264 c"notify::family".as_ptr() as *const _,
265 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
266 notify_family_trampoline::<Self, F> as *const (),
267 )),
268 Box_::into_raw(f),
269 )
270 }
271 }
272
273 #[doc(alias = "length")]
274 fn connect_length_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
275 unsafe extern "C" fn notify_length_trampoline<
276 P: IsA<InetAddressMask>,
277 F: Fn(&P) + Send + Sync + 'static,
278 >(
279 this: *mut ffi::GInetAddressMask,
280 _param_spec: glib::ffi::gpointer,
281 f: glib::ffi::gpointer,
282 ) {
283 unsafe {
284 let f: &F = &*(f as *const F);
285 f(InetAddressMask::from_glib_borrow(this).unsafe_cast_ref())
286 }
287 }
288 unsafe {
289 let f: Box_<F> = Box_::new(f);
290 connect_raw(
291 self.as_ptr() as *mut _,
292 c"notify::length".as_ptr() as *const _,
293 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
294 notify_length_trampoline::<Self, F> as *const (),
295 )),
296 Box_::into_raw(f),
297 )
298 }
299 }
300}
301
302impl<O: IsA<InetAddressMask>> InetAddressMaskExt for O {}