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 5 use crate::SocketConnectable; 6 use crate::SocketFamily; 7 use glib::object::Cast; 8 use glib::object::IsA; 9 use glib::signal::connect_raw; 10 use glib::signal::SignalHandlerId; 11 use glib::translate::*; 12 use std::boxed::Box as Box_; 13 use std::fmt; 14 use std::mem::transmute; 15 16 glib::wrapper! { 17 #[doc(alias = "GSocketAddress")] 18 pub struct SocketAddress(Object<ffi::GSocketAddress, ffi::GSocketAddressClass>) @implements SocketConnectable; 19 20 match fn { 21 type_ => || ffi::g_socket_address_get_type(), 22 } 23 } 24 25 impl SocketAddress { 26 //#[doc(alias = "g_socket_address_new_from_native")] 27 //#[doc(alias = "new_from_native")] 28 //pub fn from_native(native: /*Unimplemented*/Fundamental: Pointer, len: usize) -> SocketAddress { 29 // unsafe { TODO: call ffi:g_socket_address_new_from_native() } 30 //} 31 } 32 33 unsafe impl Send for SocketAddress {} 34 unsafe impl Sync for SocketAddress {} 35 36 pub const NONE_SOCKET_ADDRESS: Option<&SocketAddress> = None; 37 38 pub trait SocketAddressExt: 'static { 39 #[doc(alias = "g_socket_address_get_family")] 40 #[doc(alias = "get_family")] family(&self) -> SocketFamily41 fn family(&self) -> SocketFamily; 42 43 #[doc(alias = "g_socket_address_get_native_size")] 44 #[doc(alias = "get_native_size")] native_size(&self) -> isize45 fn native_size(&self) -> isize; 46 47 //#[doc(alias = "g_socket_address_to_native")] 48 //fn to_native(&self, dest: /*Unimplemented*/Option<Fundamental: Pointer>, destlen: usize) -> Result<(), glib::Error>; 49 50 #[doc(alias = "family")] connect_family_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId51 fn connect_family_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId; 52 } 53 54 impl<O: IsA<SocketAddress>> SocketAddressExt for O { family(&self) -> SocketFamily55 fn family(&self) -> SocketFamily { 56 unsafe { 57 from_glib(ffi::g_socket_address_get_family( 58 self.as_ref().to_glib_none().0, 59 )) 60 } 61 } 62 native_size(&self) -> isize63 fn native_size(&self) -> isize { 64 unsafe { ffi::g_socket_address_get_native_size(self.as_ref().to_glib_none().0) } 65 } 66 67 //fn to_native(&self, dest: /*Unimplemented*/Option<Fundamental: Pointer>, destlen: usize) -> Result<(), glib::Error> { 68 // unsafe { TODO: call ffi:g_socket_address_to_native() } 69 //} 70 connect_family_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId71 fn connect_family_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId { 72 unsafe extern "C" fn notify_family_trampoline< 73 P: IsA<SocketAddress>, 74 F: Fn(&P) + Send + Sync + 'static, 75 >( 76 this: *mut ffi::GSocketAddress, 77 _param_spec: glib::ffi::gpointer, 78 f: glib::ffi::gpointer, 79 ) { 80 let f: &F = &*(f as *const F); 81 f(SocketAddress::from_glib_borrow(this).unsafe_cast_ref()) 82 } 83 unsafe { 84 let f: Box_<F> = Box_::new(f); 85 connect_raw( 86 self.as_ptr() as *mut _, 87 b"notify::family\0".as_ptr() as *const _, 88 Some(transmute::<_, unsafe extern "C" fn()>( 89 notify_family_trampoline::<Self, F> as *const (), 90 )), 91 Box_::into_raw(f), 92 ) 93 } 94 } 95 } 96 97 impl fmt::Display for SocketAddress { fmt(&self, f: &mut fmt::Formatter) -> fmt::Result98 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 99 f.write_str("SocketAddress") 100 } 101 } 102