Skip to main content

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::{SocketConnectable, SocketFamily, ffi};
6use glib::{
7    prelude::*,
8    signal::{SignalHandlerId, connect_raw},
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            unsafe {
68                let f: &F = &*(f as *const F);
69                f(SocketAddress::from_glib_borrow(this).unsafe_cast_ref())
70            }
71        }
72        unsafe {
73            let f: Box_<F> = Box_::new(f);
74            connect_raw(
75                self.as_ptr() as *mut _,
76                c"notify::family".as_ptr(),
77                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
78                    notify_family_trampoline::<Self, F> as *const (),
79                )),
80                Box_::into_raw(f),
81            )
82        }
83    }
84}
85
86impl<O: IsA<SocketAddress>> SocketAddressExt for O {}