gio/auto/
socket_address.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, 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    //#[doc(alias = "g_socket_address_new_from_native")]
26    //#[doc(alias = "new_from_native")]
27    //pub fn from_native(native: /*Unimplemented*/Basic: Pointer, len: usize) -> SocketAddress {
28    //    unsafe { TODO: call ffi:g_socket_address_new_from_native() }
29    //}
30}
31
32unsafe impl Send for SocketAddress {}
33unsafe impl Sync for SocketAddress {}
34
35pub trait SocketAddressExt: IsA<SocketAddress> + 'static {
36    #[doc(alias = "g_socket_address_get_family")]
37    #[doc(alias = "get_family")]
38    fn family(&self) -> SocketFamily {
39        unsafe {
40            from_glib(ffi::g_socket_address_get_family(
41                self.as_ref().to_glib_none().0,
42            ))
43        }
44    }
45
46    #[doc(alias = "g_socket_address_get_native_size")]
47    #[doc(alias = "get_native_size")]
48    fn native_size(&self) -> isize {
49        unsafe { ffi::g_socket_address_get_native_size(self.as_ref().to_glib_none().0) }
50    }
51
52    //#[doc(alias = "g_socket_address_to_native")]
53    //fn to_native(&self, dest: /*Unimplemented*/Option<Basic: Pointer>, destlen: usize) -> Result<(), glib::Error> {
54    //    unsafe { TODO: call ffi:g_socket_address_to_native() }
55    //}
56
57    #[doc(alias = "family")]
58    fn connect_family_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
59        unsafe extern "C" fn notify_family_trampoline<
60            P: IsA<SocketAddress>,
61            F: Fn(&P) + Send + Sync + 'static,
62        >(
63            this: *mut ffi::GSocketAddress,
64            _param_spec: glib::ffi::gpointer,
65            f: glib::ffi::gpointer,
66        ) {
67            let f: &F = &*(f as *const F);
68            f(SocketAddress::from_glib_borrow(this).unsafe_cast_ref())
69        }
70        unsafe {
71            let f: Box_<F> = Box_::new(f);
72            connect_raw(
73                self.as_ptr() as *mut _,
74                c"notify::family".as_ptr() as *const _,
75                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
76                    notify_family_trampoline::<Self, F> as *const (),
77                )),
78                Box_::into_raw(f),
79            )
80        }
81    }
82}
83
84impl<O: IsA<SocketAddress>> SocketAddressExt for O {}