gio/auto/
inet_address_mask.rs1use gio_sys;
6use glib::object::Cast;
7use glib::object::IsA;
8use glib::signal::connect_raw;
9use glib::signal::SignalHandlerId;
10use glib::translate::*;
11use glib::GString;
12use glib::Value;
13use glib_sys;
14use gobject_sys;
15use std::boxed::Box as Box_;
16use std::fmt;
17use std::mem::transmute;
18use std::ptr;
19use Error;
20use InetAddress;
21use SocketFamily;
22
23glib_wrapper! {
24 pub struct InetAddressMask(Object<gio_sys::GInetAddressMask, gio_sys::GInetAddressMaskClass, InetAddressMaskClass>);
25
26 match fn {
27 get_type => || gio_sys::g_inet_address_mask_get_type(),
28 }
29}
30
31impl InetAddressMask {
32 pub fn new<P: IsA<InetAddress>>(addr: &P, length: u32) -> Result<InetAddressMask, Error> {
33 unsafe {
34 let mut error = ptr::null_mut();
35 let ret = gio_sys::g_inet_address_mask_new(
36 addr.as_ref().to_glib_none().0,
37 length,
38 &mut error,
39 );
40 if error.is_null() {
41 Ok(from_glib_full(ret))
42 } else {
43 Err(from_glib_full(error))
44 }
45 }
46 }
47
48 pub fn new_from_string(mask_string: &str) -> Result<InetAddressMask, Error> {
49 unsafe {
50 let mut error = ptr::null_mut();
51 let ret = gio_sys::g_inet_address_mask_new_from_string(
52 mask_string.to_glib_none().0,
53 &mut error,
54 );
55 if error.is_null() {
56 Ok(from_glib_full(ret))
57 } else {
58 Err(from_glib_full(error))
59 }
60 }
61 }
62}
63
64unsafe impl Send for InetAddressMask {}
65unsafe impl Sync for InetAddressMask {}
66
67pub const NONE_INET_ADDRESS_MASK: Option<&InetAddressMask> = None;
68
69pub trait InetAddressMaskExt: 'static {
70 fn equal<P: IsA<InetAddressMask>>(&self, mask2: &P) -> bool;
71
72 fn get_address(&self) -> InetAddress;
73
74 fn get_family(&self) -> SocketFamily;
75
76 fn get_length(&self) -> u32;
77
78 fn matches<P: IsA<InetAddress>>(&self, address: &P) -> bool;
79
80 fn to_string(&self) -> GString;
81
82 fn set_property_address(&self, address: Option<&InetAddress>);
83
84 fn set_property_length(&self, length: u32);
85
86 fn connect_property_address_notify<F: Fn(&Self) + Send + Sync + 'static>(
87 &self,
88 f: F,
89 ) -> SignalHandlerId;
90
91 fn connect_property_family_notify<F: Fn(&Self) + Send + Sync + 'static>(
92 &self,
93 f: F,
94 ) -> SignalHandlerId;
95
96 fn connect_property_length_notify<F: Fn(&Self) + Send + Sync + 'static>(
97 &self,
98 f: F,
99 ) -> SignalHandlerId;
100}
101
102impl<O: IsA<InetAddressMask>> InetAddressMaskExt for O {
103 fn equal<P: IsA<InetAddressMask>>(&self, mask2: &P) -> bool {
104 unsafe {
105 from_glib(gio_sys::g_inet_address_mask_equal(
106 self.as_ref().to_glib_none().0,
107 mask2.as_ref().to_glib_none().0,
108 ))
109 }
110 }
111
112 fn get_address(&self) -> InetAddress {
113 unsafe {
114 from_glib_none(gio_sys::g_inet_address_mask_get_address(
115 self.as_ref().to_glib_none().0,
116 ))
117 }
118 }
119
120 fn get_family(&self) -> SocketFamily {
121 unsafe {
122 from_glib(gio_sys::g_inet_address_mask_get_family(
123 self.as_ref().to_glib_none().0,
124 ))
125 }
126 }
127
128 fn get_length(&self) -> u32 {
129 unsafe { gio_sys::g_inet_address_mask_get_length(self.as_ref().to_glib_none().0) }
130 }
131
132 fn matches<P: IsA<InetAddress>>(&self, address: &P) -> bool {
133 unsafe {
134 from_glib(gio_sys::g_inet_address_mask_matches(
135 self.as_ref().to_glib_none().0,
136 address.as_ref().to_glib_none().0,
137 ))
138 }
139 }
140
141 fn to_string(&self) -> GString {
142 unsafe {
143 from_glib_full(gio_sys::g_inet_address_mask_to_string(
144 self.as_ref().to_glib_none().0,
145 ))
146 }
147 }
148
149 fn set_property_address(&self, address: Option<&InetAddress>) {
150 unsafe {
151 gobject_sys::g_object_set_property(
152 self.to_glib_none().0 as *mut gobject_sys::GObject,
153 b"address\0".as_ptr() as *const _,
154 Value::from(address).to_glib_none().0,
155 );
156 }
157 }
158
159 fn set_property_length(&self, length: u32) {
160 unsafe {
161 gobject_sys::g_object_set_property(
162 self.to_glib_none().0 as *mut gobject_sys::GObject,
163 b"length\0".as_ptr() as *const _,
164 Value::from(&length).to_glib_none().0,
165 );
166 }
167 }
168
169 fn connect_property_address_notify<F: Fn(&Self) + Send + Sync + 'static>(
170 &self,
171 f: F,
172 ) -> SignalHandlerId {
173 unsafe extern "C" fn notify_address_trampoline<P, F: Fn(&P) + Send + Sync + 'static>(
174 this: *mut gio_sys::GInetAddressMask,
175 _param_spec: glib_sys::gpointer,
176 f: glib_sys::gpointer,
177 ) where
178 P: IsA<InetAddressMask>,
179 {
180 let f: &F = &*(f as *const F);
181 f(&InetAddressMask::from_glib_borrow(this).unsafe_cast())
182 }
183 unsafe {
184 let f: Box_<F> = Box_::new(f);
185 connect_raw(
186 self.as_ptr() as *mut _,
187 b"notify::address\0".as_ptr() as *const _,
188 Some(transmute(notify_address_trampoline::<Self, F> as usize)),
189 Box_::into_raw(f),
190 )
191 }
192 }
193
194 fn connect_property_family_notify<F: Fn(&Self) + Send + Sync + 'static>(
195 &self,
196 f: F,
197 ) -> SignalHandlerId {
198 unsafe extern "C" fn notify_family_trampoline<P, F: Fn(&P) + Send + Sync + 'static>(
199 this: *mut gio_sys::GInetAddressMask,
200 _param_spec: glib_sys::gpointer,
201 f: glib_sys::gpointer,
202 ) where
203 P: IsA<InetAddressMask>,
204 {
205 let f: &F = &*(f as *const F);
206 f(&InetAddressMask::from_glib_borrow(this).unsafe_cast())
207 }
208 unsafe {
209 let f: Box_<F> = Box_::new(f);
210 connect_raw(
211 self.as_ptr() as *mut _,
212 b"notify::family\0".as_ptr() as *const _,
213 Some(transmute(notify_family_trampoline::<Self, F> as usize)),
214 Box_::into_raw(f),
215 )
216 }
217 }
218
219 fn connect_property_length_notify<F: Fn(&Self) + Send + Sync + 'static>(
220 &self,
221 f: F,
222 ) -> SignalHandlerId {
223 unsafe extern "C" fn notify_length_trampoline<P, F: Fn(&P) + Send + Sync + 'static>(
224 this: *mut gio_sys::GInetAddressMask,
225 _param_spec: glib_sys::gpointer,
226 f: glib_sys::gpointer,
227 ) where
228 P: IsA<InetAddressMask>,
229 {
230 let f: &F = &*(f as *const F);
231 f(&InetAddressMask::from_glib_borrow(this).unsafe_cast())
232 }
233 unsafe {
234 let f: Box_<F> = Box_::new(f);
235 connect_raw(
236 self.as_ptr() as *mut _,
237 b"notify::length\0".as_ptr() as *const _,
238 Some(transmute(notify_length_trampoline::<Self, F> as usize)),
239 Box_::into_raw(f),
240 )
241 }
242 }
243}
244
245impl fmt::Display for InetAddressMask {
246 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
247 write!(f, "InetAddressMask")
248 }
249}