gio/auto/
inet_address_mask.rs
1use 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")]
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 let f: &F = &*(f as *const F);
228 f(InetAddressMask::from_glib_borrow(this).unsafe_cast_ref())
229 }
230 unsafe {
231 let f: Box_<F> = Box_::new(f);
232 connect_raw(
233 self.as_ptr() as *mut _,
234 c"notify::address".as_ptr() as *const _,
235 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
236 notify_address_trampoline::<Self, F> as *const (),
237 )),
238 Box_::into_raw(f),
239 )
240 }
241 }
242
243 #[doc(alias = "family")]
244 fn connect_family_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
245 unsafe extern "C" fn notify_family_trampoline<
246 P: IsA<InetAddressMask>,
247 F: Fn(&P) + Send + Sync + 'static,
248 >(
249 this: *mut ffi::GInetAddressMask,
250 _param_spec: glib::ffi::gpointer,
251 f: glib::ffi::gpointer,
252 ) {
253 let f: &F = &*(f as *const F);
254 f(InetAddressMask::from_glib_borrow(this).unsafe_cast_ref())
255 }
256 unsafe {
257 let f: Box_<F> = Box_::new(f);
258 connect_raw(
259 self.as_ptr() as *mut _,
260 c"notify::family".as_ptr() as *const _,
261 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
262 notify_family_trampoline::<Self, F> as *const (),
263 )),
264 Box_::into_raw(f),
265 )
266 }
267 }
268
269 #[doc(alias = "length")]
270 fn connect_length_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
271 unsafe extern "C" fn notify_length_trampoline<
272 P: IsA<InetAddressMask>,
273 F: Fn(&P) + Send + Sync + 'static,
274 >(
275 this: *mut ffi::GInetAddressMask,
276 _param_spec: glib::ffi::gpointer,
277 f: glib::ffi::gpointer,
278 ) {
279 let f: &F = &*(f as *const F);
280 f(InetAddressMask::from_glib_borrow(this).unsafe_cast_ref())
281 }
282 unsafe {
283 let f: Box_<F> = Box_::new(f);
284 connect_raw(
285 self.as_ptr() as *mut _,
286 c"notify::length".as_ptr() as *const _,
287 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
288 notify_length_trampoline::<Self, F> as *const (),
289 )),
290 Box_::into_raw(f),
291 )
292 }
293 }
294}
295
296impl<O: IsA<InetAddressMask>> InetAddressMaskExt for O {}