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 crate::{ffi, InetAddress, SocketAddress, SocketConnectable};
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9 /// An IPv4 or IPv6 socket address. That is, the combination of a
10 /// [`InetAddress`][crate::InetAddress] and a port number.
11 ///
12 /// In UNIX terms, `GInetSocketAddress` corresponds to a
13 /// [`struct sockaddr_in` or `struct sockaddr_in6`](man:sockaddr(3type)).
14 ///
15 /// ## Properties
16 ///
17 ///
18 /// #### `address`
19 /// The address.
20 ///
21 /// Readable | Writeable | Construct Only
22 ///
23 ///
24 /// #### `flowinfo`
25 /// The `sin6_flowinfo` field, for IPv6 addresses.
26 ///
27 /// Readable | Writeable | Construct Only
28 ///
29 ///
30 /// #### `port`
31 /// The port.
32 ///
33 /// Readable | Writeable | Construct Only
34 ///
35 ///
36 /// #### `scope-id`
37 /// The `sin6_scope_id` field, for IPv6 addresses.
38 ///
39 /// Readable | Writeable | Construct Only
40 /// <details><summary><h4>SocketAddress</h4></summary>
41 ///
42 ///
43 /// #### `family`
44 /// The family of the socket address.
45 ///
46 /// Readable
47 /// </details>
48 ///
49 /// # Implements
50 ///
51 /// [`InetSocketAddressExt`][trait@crate::prelude::InetSocketAddressExt], [`SocketAddressExt`][trait@crate::prelude::SocketAddressExt], [`trait@glib::ObjectExt`], [`SocketConnectableExt`][trait@crate::prelude::SocketConnectableExt]
52 #[doc(alias = "GInetSocketAddress")]
53 pub struct InetSocketAddress(Object<ffi::GInetSocketAddress, ffi::GInetSocketAddressClass>) @extends SocketAddress, @implements SocketConnectable;
54
55 match fn {
56 type_ => || ffi::g_inet_socket_address_get_type(),
57 }
58}
59
60impl InetSocketAddress {
61 pub const NONE: Option<&'static InetSocketAddress> = None;
62
63 /// Creates a new #GInetSocketAddress for @address and @port.
64 /// ## `address`
65 /// a #GInetAddress
66 /// ## `port`
67 /// a port number
68 ///
69 /// # Returns
70 ///
71 /// a new #GInetSocketAddress
72 #[doc(alias = "g_inet_socket_address_new")]
73 pub fn new(address: &impl IsA<InetAddress>, port: u16) -> InetSocketAddress {
74 unsafe {
75 SocketAddress::from_glib_full(ffi::g_inet_socket_address_new(
76 address.as_ref().to_glib_none().0,
77 port,
78 ))
79 .unsafe_cast()
80 }
81 }
82
83 /// Creates a new #GInetSocketAddress for @address and @port.
84 ///
85 /// If @address is an IPv6 address, it can also contain a scope ID
86 /// (separated from the address by a `%`).
87 /// ## `address`
88 /// the string form of an IP address
89 /// ## `port`
90 /// a port number
91 ///
92 /// # Returns
93 ///
94 /// a new #GInetSocketAddress,
95 /// or [`None`] if @address cannot be parsed.
96 #[doc(alias = "g_inet_socket_address_new_from_string")]
97 #[doc(alias = "new_from_string")]
98 pub fn from_string(address: &str, port: u32) -> Option<InetSocketAddress> {
99 unsafe {
100 Option::<SocketAddress>::from_glib_full(ffi::g_inet_socket_address_new_from_string(
101 address.to_glib_none().0,
102 port,
103 ))
104 .map(|o| o.unsafe_cast())
105 }
106 }
107}
108
109unsafe impl Send for InetSocketAddress {}
110unsafe impl Sync for InetSocketAddress {}
111
112mod sealed {
113 pub trait Sealed {}
114 impl<T: super::IsA<super::InetSocketAddress>> Sealed for T {}
115}
116
117/// Trait containing all [`struct@InetSocketAddress`] methods.
118///
119/// # Implementors
120///
121/// [`InetSocketAddress`][struct@crate::InetSocketAddress], [`ProxyAddress`][struct@crate::ProxyAddress]
122pub trait InetSocketAddressExt: IsA<InetSocketAddress> + sealed::Sealed + 'static {
123 /// Gets @self's #GInetAddress.
124 ///
125 /// # Returns
126 ///
127 /// the #GInetAddress for @self, which must be
128 /// g_object_ref()'d if it will be stored
129 #[doc(alias = "g_inet_socket_address_get_address")]
130 #[doc(alias = "get_address")]
131 fn address(&self) -> InetAddress {
132 unsafe {
133 from_glib_none(ffi::g_inet_socket_address_get_address(
134 self.as_ref().to_glib_none().0,
135 ))
136 }
137 }
138
139 /// Gets the `sin6_flowinfo` field from @self,
140 /// which must be an IPv6 address.
141 ///
142 /// # Returns
143 ///
144 /// the flowinfo field
145 #[doc(alias = "g_inet_socket_address_get_flowinfo")]
146 #[doc(alias = "get_flowinfo")]
147 fn flowinfo(&self) -> u32 {
148 unsafe { ffi::g_inet_socket_address_get_flowinfo(self.as_ref().to_glib_none().0) }
149 }
150
151 /// Gets @self's port.
152 ///
153 /// # Returns
154 ///
155 /// the port for @self
156 #[doc(alias = "g_inet_socket_address_get_port")]
157 #[doc(alias = "get_port")]
158 fn port(&self) -> u16 {
159 unsafe { ffi::g_inet_socket_address_get_port(self.as_ref().to_glib_none().0) }
160 }
161
162 /// Gets the `sin6_scope_id` field from @self,
163 /// which must be an IPv6 address.
164 ///
165 /// # Returns
166 ///
167 /// the scope id field
168 #[doc(alias = "g_inet_socket_address_get_scope_id")]
169 #[doc(alias = "get_scope_id")]
170 #[doc(alias = "scope-id")]
171 fn scope_id(&self) -> u32 {
172 unsafe { ffi::g_inet_socket_address_get_scope_id(self.as_ref().to_glib_none().0) }
173 }
174}
175
176impl<O: IsA<InetSocketAddress>> InetSocketAddressExt for O {}