gio/auto/
socket_address.rs1use crate::{ffi, SocketConnectable, 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 = "GSocketAddress")]
15 pub struct SocketAddress(Object<ffi::GSocketAddress, ffi::GSocketAddressClass>) @implements SocketConnectable;
16
17 match fn {
18 type_ => || ffi::g_socket_address_get_type(),
19 }
20}
21
22impl SocketAddress {
23 pub const NONE: Option<&'static SocketAddress> = None;
24
25 }
31
32unsafe impl Send for SocketAddress {}
33unsafe impl Sync for SocketAddress {}
34
35mod sealed {
36 pub trait Sealed {}
37 impl<T: super::IsA<super::SocketAddress>> Sealed for T {}
38}
39
40pub trait SocketAddressExt: IsA<SocketAddress> + sealed::Sealed + 'static {
41 #[doc(alias = "g_socket_address_get_family")]
42 #[doc(alias = "get_family")]
43 fn family(&self) -> SocketFamily {
44 unsafe {
45 from_glib(ffi::g_socket_address_get_family(
46 self.as_ref().to_glib_none().0,
47 ))
48 }
49 }
50
51 #[doc(alias = "g_socket_address_get_native_size")]
52 #[doc(alias = "get_native_size")]
53 fn native_size(&self) -> isize {
54 unsafe { ffi::g_socket_address_get_native_size(self.as_ref().to_glib_none().0) }
55 }
56
57 #[doc(alias = "family")]
63 fn connect_family_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
64 unsafe extern "C" fn notify_family_trampoline<
65 P: IsA<SocketAddress>,
66 F: Fn(&P) + Send + Sync + 'static,
67 >(
68 this: *mut ffi::GSocketAddress,
69 _param_spec: glib::ffi::gpointer,
70 f: glib::ffi::gpointer,
71 ) {
72 let f: &F = &*(f as *const F);
73 f(SocketAddress::from_glib_borrow(this).unsafe_cast_ref())
74 }
75 unsafe {
76 let f: Box_<F> = Box_::new(f);
77 connect_raw(
78 self.as_ptr() as *mut _,
79 b"notify::family\0".as_ptr() as *const _,
80 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
81 notify_family_trampoline::<Self, F> as *const (),
82 )),
83 Box_::into_raw(f),
84 )
85 }
86 }
87}
88
89impl<O: IsA<SocketAddress>> SocketAddressExt for O {}