gio/auto/
inet_socket_address.rs1use crate::{ffi, InetAddress, SocketAddress, SocketConnectable};
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9 #[doc(alias = "GInetSocketAddress")]
10 pub struct InetSocketAddress(Object<ffi::GInetSocketAddress, ffi::GInetSocketAddressClass>) @extends SocketAddress, @implements SocketConnectable;
11
12 match fn {
13 type_ => || ffi::g_inet_socket_address_get_type(),
14 }
15}
16
17impl InetSocketAddress {
18 pub const NONE: Option<&'static InetSocketAddress> = None;
19
20 #[doc(alias = "g_inet_socket_address_new")]
21 pub fn new(address: &impl IsA<InetAddress>, port: u16) -> InetSocketAddress {
22 unsafe {
23 SocketAddress::from_glib_full(ffi::g_inet_socket_address_new(
24 address.as_ref().to_glib_none().0,
25 port,
26 ))
27 .unsafe_cast()
28 }
29 }
30
31 #[doc(alias = "g_inet_socket_address_new_from_string")]
32 #[doc(alias = "new_from_string")]
33 pub fn from_string(address: &str, port: u32) -> Option<InetSocketAddress> {
34 unsafe {
35 Option::<SocketAddress>::from_glib_full(ffi::g_inet_socket_address_new_from_string(
36 address.to_glib_none().0,
37 port,
38 ))
39 .map(|o| o.unsafe_cast())
40 }
41 }
42}
43
44unsafe impl Send for InetSocketAddress {}
45unsafe impl Sync for InetSocketAddress {}
46
47pub trait InetSocketAddressExt: IsA<InetSocketAddress> + 'static {
48 #[doc(alias = "g_inet_socket_address_get_address")]
49 #[doc(alias = "get_address")]
50 fn address(&self) -> InetAddress {
51 unsafe {
52 from_glib_none(ffi::g_inet_socket_address_get_address(
53 self.as_ref().to_glib_none().0,
54 ))
55 }
56 }
57
58 #[doc(alias = "g_inet_socket_address_get_flowinfo")]
59 #[doc(alias = "get_flowinfo")]
60 fn flowinfo(&self) -> u32 {
61 unsafe { ffi::g_inet_socket_address_get_flowinfo(self.as_ref().to_glib_none().0) }
62 }
63
64 #[doc(alias = "g_inet_socket_address_get_port")]
65 #[doc(alias = "get_port")]
66 fn port(&self) -> u16 {
67 unsafe { ffi::g_inet_socket_address_get_port(self.as_ref().to_glib_none().0) }
68 }
69
70 #[doc(alias = "g_inet_socket_address_get_scope_id")]
71 #[doc(alias = "get_scope_id")]
72 #[doc(alias = "scope-id")]
73 fn scope_id(&self) -> u32 {
74 unsafe { ffi::g_inet_socket_address_get_scope_id(self.as_ref().to_glib_none().0) }
75 }
76}
77
78impl<O: IsA<InetSocketAddress>> InetSocketAddressExt for O {}