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
114mod sealed {
115 pub trait Sealed {}
116 impl<T: super::IsA<super::InetAddressMask>> Sealed for T {}
117}
118
119pub trait InetAddressMaskExt: IsA<InetAddressMask> + sealed::Sealed + 'static {
125 #[doc(alias = "g_inet_address_mask_equal")]
126 fn equal(&self, mask2: &impl IsA<InetAddressMask>) -> bool {
127 unsafe {
128 from_glib(ffi::g_inet_address_mask_equal(
129 self.as_ref().to_glib_none().0,
130 mask2.as_ref().to_glib_none().0,
131 ))
132 }
133 }
134
135 #[doc(alias = "g_inet_address_mask_get_address")]
141 #[doc(alias = "get_address")]
142 fn address(&self) -> InetAddress {
143 unsafe {
144 from_glib_none(ffi::g_inet_address_mask_get_address(
145 self.as_ref().to_glib_none().0,
146 ))
147 }
148 }
149
150 #[doc(alias = "g_inet_address_mask_get_family")]
156 #[doc(alias = "get_family")]
157 fn family(&self) -> SocketFamily {
158 unsafe {
159 from_glib(ffi::g_inet_address_mask_get_family(
160 self.as_ref().to_glib_none().0,
161 ))
162 }
163 }
164
165 #[doc(alias = "g_inet_address_mask_get_length")]
171 #[doc(alias = "get_length")]
172 fn length(&self) -> u32 {
173 unsafe { ffi::g_inet_address_mask_get_length(self.as_ref().to_glib_none().0) }
174 }
175
176 #[doc(alias = "g_inet_address_mask_matches")]
185 fn matches(&self, address: &impl IsA<InetAddress>) -> bool {
186 unsafe {
187 from_glib(ffi::g_inet_address_mask_matches(
188 self.as_ref().to_glib_none().0,
189 address.as_ref().to_glib_none().0,
190 ))
191 }
192 }
193
194 #[doc(alias = "g_inet_address_mask_to_string")]
200 #[doc(alias = "to_string")]
201 fn to_str(&self) -> glib::GString {
202 unsafe {
203 from_glib_full(ffi::g_inet_address_mask_to_string(
204 self.as_ref().to_glib_none().0,
205 ))
206 }
207 }
208
209 fn set_address<P: IsA<InetAddress>>(&self, address: Option<&P>) {
211 ObjectExt::set_property(self.as_ref(), "address", address)
212 }
213
214 fn set_length(&self, length: u32) {
216 ObjectExt::set_property(self.as_ref(), "length", length)
217 }
218
219 #[doc(alias = "address")]
220 fn connect_address_notify<F: Fn(&Self) + Send + Sync + 'static>(
221 &self,
222 f: F,
223 ) -> SignalHandlerId {
224 unsafe extern "C" fn notify_address_trampoline<
225 P: IsA<InetAddressMask>,
226 F: Fn(&P) + Send + Sync + 'static,
227 >(
228 this: *mut ffi::GInetAddressMask,
229 _param_spec: glib::ffi::gpointer,
230 f: glib::ffi::gpointer,
231 ) {
232 let f: &F = &*(f as *const F);
233 f(InetAddressMask::from_glib_borrow(this).unsafe_cast_ref())
234 }
235 unsafe {
236 let f: Box_<F> = Box_::new(f);
237 connect_raw(
238 self.as_ptr() as *mut _,
239 b"notify::address\0".as_ptr() as *const _,
240 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
241 notify_address_trampoline::<Self, F> as *const (),
242 )),
243 Box_::into_raw(f),
244 )
245 }
246 }
247
248 #[doc(alias = "family")]
249 fn connect_family_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
250 unsafe extern "C" fn notify_family_trampoline<
251 P: IsA<InetAddressMask>,
252 F: Fn(&P) + Send + Sync + 'static,
253 >(
254 this: *mut ffi::GInetAddressMask,
255 _param_spec: glib::ffi::gpointer,
256 f: glib::ffi::gpointer,
257 ) {
258 let f: &F = &*(f as *const F);
259 f(InetAddressMask::from_glib_borrow(this).unsafe_cast_ref())
260 }
261 unsafe {
262 let f: Box_<F> = Box_::new(f);
263 connect_raw(
264 self.as_ptr() as *mut _,
265 b"notify::family\0".as_ptr() as *const _,
266 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
267 notify_family_trampoline::<Self, F> as *const (),
268 )),
269 Box_::into_raw(f),
270 )
271 }
272 }
273
274 #[doc(alias = "length")]
275 fn connect_length_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
276 unsafe extern "C" fn notify_length_trampoline<
277 P: IsA<InetAddressMask>,
278 F: Fn(&P) + Send + Sync + 'static,
279 >(
280 this: *mut ffi::GInetAddressMask,
281 _param_spec: glib::ffi::gpointer,
282 f: glib::ffi::gpointer,
283 ) {
284 let f: &F = &*(f as *const F);
285 f(InetAddressMask::from_glib_borrow(this).unsafe_cast_ref())
286 }
287 unsafe {
288 let f: Box_<F> = Box_::new(f);
289 connect_raw(
290 self.as_ptr() as *mut _,
291 b"notify::length\0".as_ptr() as *const _,
292 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
293 notify_length_trampoline::<Self, F> as *const (),
294 )),
295 Box_::into_raw(f),
296 )
297 }
298 }
299}
300
301impl<O: IsA<InetAddressMask>> InetAddressMaskExt for O {}