gio/auto/
inet_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 gio_sys;
6use glib::object::Cast;
7use glib::object::IsA;
8use glib::translate::*;
9use std::fmt;
10use InetAddress;
11use SocketAddress;
12use SocketConnectable;
13
14glib_wrapper! {
15    pub struct InetSocketAddress(Object<gio_sys::GInetSocketAddress, gio_sys::GInetSocketAddressClass, InetSocketAddressClass>) @extends SocketAddress, @implements SocketConnectable;
16
17    match fn {
18        get_type => || gio_sys::g_inet_socket_address_get_type(),
19    }
20}
21
22impl InetSocketAddress {
23    pub fn new<P: IsA<InetAddress>>(address: &P, port: u16) -> InetSocketAddress {
24        unsafe {
25            SocketAddress::from_glib_full(gio_sys::g_inet_socket_address_new(
26                address.as_ref().to_glib_none().0,
27                port,
28            ))
29            .unsafe_cast()
30        }
31    }
32
33    pub fn new_from_string(address: &str, port: u32) -> InetSocketAddress {
34        unsafe {
35            SocketAddress::from_glib_full(gio_sys::g_inet_socket_address_new_from_string(
36                address.to_glib_none().0,
37                port,
38            ))
39            .unsafe_cast()
40        }
41    }
42}
43
44unsafe impl Send for InetSocketAddress {}
45unsafe impl Sync for InetSocketAddress {}
46
47pub const NONE_INET_SOCKET_ADDRESS: Option<&InetSocketAddress> = None;
48
49pub trait InetSocketAddressExt: 'static {
50    fn get_address(&self) -> Option<InetAddress>;
51
52    fn get_flowinfo(&self) -> u32;
53
54    fn get_port(&self) -> u16;
55
56    fn get_scope_id(&self) -> u32;
57}
58
59impl<O: IsA<InetSocketAddress>> InetSocketAddressExt for O {
60    fn get_address(&self) -> Option<InetAddress> {
61        unsafe {
62            from_glib_none(gio_sys::g_inet_socket_address_get_address(
63                self.as_ref().to_glib_none().0,
64            ))
65        }
66    }
67
68    fn get_flowinfo(&self) -> u32 {
69        unsafe { gio_sys::g_inet_socket_address_get_flowinfo(self.as_ref().to_glib_none().0) }
70    }
71
72    fn get_port(&self) -> u16 {
73        unsafe { gio_sys::g_inet_socket_address_get_port(self.as_ref().to_glib_none().0) }
74    }
75
76    fn get_scope_id(&self) -> u32 {
77        unsafe { gio_sys::g_inet_socket_address_get_scope_id(self.as_ref().to_glib_none().0) }
78    }
79}
80
81impl fmt::Display for InetSocketAddress {
82    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
83        write!(f, "InetSocketAddress")
84    }
85}