gio/auto/
inet_address_mask.rs

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
5use crate::{ffi, InetAddress, Initable, SocketFamily};
6use glib::{
7    prelude::*,
8    signal::{connect_raw, SignalHandlerId},
9    translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14    #[doc(alias = "GInetAddressMask")]
15    pub struct InetAddressMask(Object<ffi::GInetAddressMask, ffi::GInetAddressMaskClass>) @implements Initable;
16
17    match fn {
18        type_ => || ffi::g_inet_address_mask_get_type(),
19    }
20}
21
22impl InetAddressMask {
23    pub const NONE: Option<&'static InetAddressMask> = None;
24
25    #[doc(alias = "g_inet_address_mask_new")]
26    pub fn new(addr: &impl IsA<InetAddress>, length: u32) -> Result<InetAddressMask, glib::Error> {
27        unsafe {
28            let mut error = std::ptr::null_mut();
29            let ret =
30                ffi::g_inet_address_mask_new(addr.as_ref().to_glib_none().0, length, &mut error);
31            if error.is_null() {
32                Ok(from_glib_full(ret))
33            } else {
34                Err(from_glib_full(error))
35            }
36        }
37    }
38
39    #[doc(alias = "g_inet_address_mask_new_from_string")]
40    #[doc(alias = "new_from_string")]
41    pub fn from_string(mask_string: &str) -> Result<InetAddressMask, glib::Error> {
42        unsafe {
43            let mut error = std::ptr::null_mut();
44            let ret =
45                ffi::g_inet_address_mask_new_from_string(mask_string.to_glib_none().0, &mut error);
46            if error.is_null() {
47                Ok(from_glib_full(ret))
48            } else {
49                Err(from_glib_full(error))
50            }
51        }
52    }
53}
54
55impl std::fmt::Display for InetAddressMask {
56    #[inline]
57    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
58        f.write_str(&InetAddressMaskExt::to_str(self))
59    }
60}
61
62unsafe impl Send for InetAddressMask {}
63unsafe impl Sync for InetAddressMask {}
64
65pub trait InetAddressMaskExt: IsA<InetAddressMask> + 'static {
66    #[doc(alias = "g_inet_address_mask_equal")]
67    fn equal(&self, mask2: &impl IsA<InetAddressMask>) -> bool {
68        unsafe {
69            from_glib(ffi::g_inet_address_mask_equal(
70                self.as_ref().to_glib_none().0,
71                mask2.as_ref().to_glib_none().0,
72            ))
73        }
74    }
75
76    #[doc(alias = "g_inet_address_mask_get_address")]
77    #[doc(alias = "get_address")]
78    fn address(&self) -> InetAddress {
79        unsafe {
80            from_glib_none(ffi::g_inet_address_mask_get_address(
81                self.as_ref().to_glib_none().0,
82            ))
83        }
84    }
85
86    #[doc(alias = "g_inet_address_mask_get_family")]
87    #[doc(alias = "get_family")]
88    fn family(&self) -> SocketFamily {
89        unsafe {
90            from_glib(ffi::g_inet_address_mask_get_family(
91                self.as_ref().to_glib_none().0,
92            ))
93        }
94    }
95
96    #[doc(alias = "g_inet_address_mask_get_length")]
97    #[doc(alias = "get_length")]
98    fn length(&self) -> u32 {
99        unsafe { ffi::g_inet_address_mask_get_length(self.as_ref().to_glib_none().0) }
100    }
101
102    #[doc(alias = "g_inet_address_mask_matches")]
103    fn matches(&self, address: &impl IsA<InetAddress>) -> bool {
104        unsafe {
105            from_glib(ffi::g_inet_address_mask_matches(
106                self.as_ref().to_glib_none().0,
107                address.as_ref().to_glib_none().0,
108            ))
109        }
110    }
111
112    #[doc(alias = "g_inet_address_mask_to_string")]
113    #[doc(alias = "to_string")]
114    fn to_str(&self) -> glib::GString {
115        unsafe {
116            from_glib_full(ffi::g_inet_address_mask_to_string(
117                self.as_ref().to_glib_none().0,
118            ))
119        }
120    }
121
122    fn set_address<P: IsA<InetAddress>>(&self, address: Option<&P>) {
123        ObjectExt::set_property(self.as_ref(), "address", address)
124    }
125
126    fn set_length(&self, length: u32) {
127        ObjectExt::set_property(self.as_ref(), "length", length)
128    }
129
130    #[doc(alias = "address")]
131    fn connect_address_notify<F: Fn(&Self) + Send + Sync + 'static>(
132        &self,
133        f: F,
134    ) -> SignalHandlerId {
135        unsafe extern "C" fn notify_address_trampoline<
136            P: IsA<InetAddressMask>,
137            F: Fn(&P) + Send + Sync + 'static,
138        >(
139            this: *mut ffi::GInetAddressMask,
140            _param_spec: glib::ffi::gpointer,
141            f: glib::ffi::gpointer,
142        ) {
143            let f: &F = &*(f as *const F);
144            f(InetAddressMask::from_glib_borrow(this).unsafe_cast_ref())
145        }
146        unsafe {
147            let f: Box_<F> = Box_::new(f);
148            connect_raw(
149                self.as_ptr() as *mut _,
150                c"notify::address".as_ptr() as *const _,
151                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
152                    notify_address_trampoline::<Self, F> as *const (),
153                )),
154                Box_::into_raw(f),
155            )
156        }
157    }
158
159    #[doc(alias = "family")]
160    fn connect_family_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
161        unsafe extern "C" fn notify_family_trampoline<
162            P: IsA<InetAddressMask>,
163            F: Fn(&P) + Send + Sync + 'static,
164        >(
165            this: *mut ffi::GInetAddressMask,
166            _param_spec: glib::ffi::gpointer,
167            f: glib::ffi::gpointer,
168        ) {
169            let f: &F = &*(f as *const F);
170            f(InetAddressMask::from_glib_borrow(this).unsafe_cast_ref())
171        }
172        unsafe {
173            let f: Box_<F> = Box_::new(f);
174            connect_raw(
175                self.as_ptr() as *mut _,
176                c"notify::family".as_ptr() as *const _,
177                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
178                    notify_family_trampoline::<Self, F> as *const (),
179                )),
180                Box_::into_raw(f),
181            )
182        }
183    }
184
185    #[doc(alias = "length")]
186    fn connect_length_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
187        unsafe extern "C" fn notify_length_trampoline<
188            P: IsA<InetAddressMask>,
189            F: Fn(&P) + Send + Sync + 'static,
190        >(
191            this: *mut ffi::GInetAddressMask,
192            _param_spec: glib::ffi::gpointer,
193            f: glib::ffi::gpointer,
194        ) {
195            let f: &F = &*(f as *const F);
196            f(InetAddressMask::from_glib_borrow(this).unsafe_cast_ref())
197        }
198        unsafe {
199            let f: Box_<F> = Box_::new(f);
200            connect_raw(
201                self.as_ptr() as *mut _,
202                c"notify::length".as_ptr() as *const _,
203                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
204                    notify_length_trampoline::<Self, F> as *const (),
205                )),
206                Box_::into_raw(f),
207            )
208        }
209    }
210}
211
212impl<O: IsA<InetAddressMask>> InetAddressMaskExt for O {}