nm_rs/auto/
ip_route.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir
3// from gtk-girs (https://github.com/gtk-rs/gir-files)
4// DO NOT EDIT
5
6use crate::{ffi};
7#[cfg(feature = "v1_8")]
8#[cfg_attr(docsrs, doc(cfg(feature = "v1_8")))]
9use crate::{VariantAttributeSpec};
10use glib::{translate::*};
11
12glib::wrapper! {
13    #[derive(Debug, PartialOrd, Ord, Hash)]
14    pub struct IPRoute(Shared<ffi::NMIPRoute>);
15
16    match fn {
17        ref => |ptr| ffi::nm_ip_route_ref(ptr),
18        unref => |ptr| ffi::nm_ip_route_unref(ptr),
19        type_ => || ffi::nm_ip_route_get_type(),
20    }
21}
22
23impl IPRoute {
24    /// Creates a new #NMIPRoute object.
25    /// ## `family`
26    /// the IP address family (<literal>AF_INET</literal> or
27    ///   <literal>AF_INET6</literal>)
28    /// ## `dest`
29    /// the IP address of the route's destination
30    /// ## `prefix`
31    /// the address prefix length
32    /// ## `next_hop`
33    /// the IP address of the next hop (or [`None`])
34    /// ## `metric`
35    /// the route metric (or -1 for "default")
36    ///
37    /// # Returns
38    ///
39    /// the new #NMIPRoute object, or [`None`] on error
40    #[doc(alias = "nm_ip_route_new")]
41    pub fn new(family: i32, dest: &str, prefix: u32, next_hop: Option<&str>, metric: i64) -> Result<IPRoute, glib::Error> {
42        assert_initialized_main_thread!();
43        unsafe {
44            let mut error = std::ptr::null_mut();
45            let ret = ffi::nm_ip_route_new(family, dest.to_glib_none().0, prefix, next_hop.to_glib_none().0, metric, &mut error);
46            if error.is_null() { Ok(from_glib_full(ret)) } else { Err(from_glib_full(error)) }
47        }
48    }
49
50    //#[doc(alias = "nm_ip_route_new_binary")]
51    //pub fn new_binary(family: i32, dest: /*Unimplemented*/Option<Basic: Pointer>, prefix: u32, next_hop: /*Unimplemented*/Option<Basic: Pointer>, metric: i64) -> Result<IPRoute, glib::Error> {
52    //    unsafe { TODO: call ffi:nm_ip_route_new_binary() }
53    //}
54
55    /// Creates a copy of @self
56    ///
57    /// # Returns
58    ///
59    /// a copy of @self
60    ///
61    /// This API was part of public headers before 1.32.0 but
62    /// was erroneously not exported in the ABI. It is thus only
63    /// usable since 1.32.0.
64    #[cfg(feature = "v1_32")]
65    #[cfg_attr(docsrs, doc(cfg(feature = "v1_32")))]
66    #[doc(alias = "nm_ip_route_dup")]
67#[must_use]
68    pub fn dup(&self) -> IPRoute {
69        unsafe {
70            from_glib_full(ffi::nm_ip_route_dup(self.to_glib_none().0))
71        }
72    }
73
74    #[doc(alias = "nm_ip_route_equal")]
75     fn equal(&self, other: &IPRoute) -> bool {
76        unsafe {
77            from_glib(ffi::nm_ip_route_equal(self.to_glib_none().0, other.to_glib_none().0))
78        }
79    }
80
81    /// Determines if two #NMIPRoute objects contain the same destination, prefix,
82    /// next hop, and metric.
83    /// ## `other`
84    /// the #NMIPRoute to compare @self to.
85    /// ## `cmp_flags`
86    /// tune how to compare attributes. Currently, only
87    ///   NM_IP_ROUTE_EQUAL_CMP_FLAGS_NONE (0) and NM_IP_ROUTE_EQUAL_CMP_FLAGS_WITH_ATTRS (1)
88    ///   is supported.
89    ///
90    /// # Returns
91    ///
92    /// [`true`] if the objects contain the same values, [`false`] if they do not.
93    #[cfg(feature = "v1_10")]
94    #[cfg_attr(docsrs, doc(cfg(feature = "v1_10")))]
95    #[doc(alias = "nm_ip_route_equal_full")]
96    pub fn equal_full(&self, other: &IPRoute, cmp_flags: u32) -> bool {
97        unsafe {
98            from_glib(ffi::nm_ip_route_equal_full(self.to_glib_none().0, other.to_glib_none().0, cmp_flags))
99        }
100    }
101
102    //#[doc(alias = "nm_ip_route_get_attribute")]
103    //#[doc(alias = "get_attribute")]
104    //pub fn attribute(&self, name: &str) -> /*Ignored*/glib::Variant {
105    //    unsafe { TODO: call ffi:nm_ip_route_get_attribute() }
106    //}
107
108    /// Gets an array of attribute names defined on @self.
109    ///
110    /// # Returns
111    ///
112    /// a [`None`]-terminated array of attribute names
113    #[doc(alias = "nm_ip_route_get_attribute_names")]
114    #[doc(alias = "get_attribute_names")]
115    pub fn attribute_names(&self) -> Vec<glib::GString> {
116        unsafe {
117            FromGlibPtrContainer::from_glib_full(ffi::nm_ip_route_get_attribute_names(self.to_glib_none().0))
118        }
119    }
120
121    /// Gets the IP destination address property of this route object.
122    ///
123    /// # Returns
124    ///
125    /// the IP address of the route's destination
126    #[doc(alias = "nm_ip_route_get_dest")]
127    #[doc(alias = "get_dest")]
128    pub fn dest(&self) -> glib::GString {
129        unsafe {
130            from_glib_none(ffi::nm_ip_route_get_dest(self.to_glib_none().0))
131        }
132    }
133
134    //#[doc(alias = "nm_ip_route_get_dest_binary")]
135    //#[doc(alias = "get_dest_binary")]
136    //pub fn dest_binary(&self, dest: /*Unimplemented*/Option<Basic: Pointer>) {
137    //    unsafe { TODO: call ffi:nm_ip_route_get_dest_binary() }
138    //}
139
140    /// Gets the IP address family (eg, AF_INET) property of this route
141    /// object.
142    ///
143    /// # Returns
144    ///
145    /// the IP address family
146    #[doc(alias = "nm_ip_route_get_family")]
147    #[doc(alias = "get_family")]
148    pub fn family(&self) -> i32 {
149        unsafe {
150            ffi::nm_ip_route_get_family(self.to_glib_none().0)
151        }
152    }
153
154    /// Gets the route metric property of this route object; lower values
155    /// indicate "better" or more preferred routes; -1 indicates "default"
156    /// (meaning NetworkManager will set it appropriately).
157    ///
158    /// # Returns
159    ///
160    /// the route metric
161    #[doc(alias = "nm_ip_route_get_metric")]
162    #[doc(alias = "get_metric")]
163    pub fn metric(&self) -> i64 {
164        unsafe {
165            ffi::nm_ip_route_get_metric(self.to_glib_none().0)
166        }
167    }
168
169    /// Gets the IP address of the next hop of this route; this will be [`None`] if the
170    /// route has no next hop.
171    ///
172    /// # Returns
173    ///
174    /// the IP address of the next hop, or [`None`] if this is a device route.
175    #[doc(alias = "nm_ip_route_get_next_hop")]
176    #[doc(alias = "get_next_hop")]
177    pub fn next_hop(&self) -> glib::GString {
178        unsafe {
179            from_glib_none(ffi::nm_ip_route_get_next_hop(self.to_glib_none().0))
180        }
181    }
182
183    //#[doc(alias = "nm_ip_route_get_next_hop_binary")]
184    //#[doc(alias = "get_next_hop_binary")]
185    //pub fn is_next_hop_binary(&self, next_hop: /*Unimplemented*/Option<Basic: Pointer>) -> bool {
186    //    unsafe { TODO: call ffi:nm_ip_route_get_next_hop_binary() }
187    //}
188
189    /// Gets the IP prefix (ie "24" or "30" etc) of this route.
190    ///
191    /// # Returns
192    ///
193    /// the IP prefix
194    #[doc(alias = "nm_ip_route_get_prefix")]
195    #[doc(alias = "get_prefix")]
196    pub fn prefix(&self) -> u32 {
197        unsafe {
198            ffi::nm_ip_route_get_prefix(self.to_glib_none().0)
199        }
200    }
201
202    //#[doc(alias = "nm_ip_route_set_attribute")]
203    //pub fn set_attribute(&self, name: &str, value: /*Ignored*/Option<&glib::Variant>) {
204    //    unsafe { TODO: call ffi:nm_ip_route_set_attribute() }
205    //}
206
207    /// Sets the destination property of this route object.
208    ///
209    /// @dest must be a valid address of @self's family. If you aren't sure you
210    /// have a valid address, use nm_inet_is_valid() to check it.
211    /// ## `dest`
212    /// the route's destination, as a string
213    #[doc(alias = "nm_ip_route_set_dest")]
214    pub fn set_dest(&self, dest: &str) {
215        unsafe {
216            ffi::nm_ip_route_set_dest(self.to_glib_none().0, dest.to_glib_none().0);
217        }
218    }
219
220    //#[doc(alias = "nm_ip_route_set_dest_binary")]
221    //pub fn set_dest_binary(&self, dest: /*Unimplemented*/Option<Basic: Pointer>) {
222    //    unsafe { TODO: call ffi:nm_ip_route_set_dest_binary() }
223    //}
224
225    /// Sets the metric property of this route object.
226    /// ## `metric`
227    /// the route metric (or -1 for "default")
228    #[doc(alias = "nm_ip_route_set_metric")]
229    pub fn set_metric(&self, metric: i64) {
230        unsafe {
231            ffi::nm_ip_route_set_metric(self.to_glib_none().0, metric);
232        }
233    }
234
235    /// Sets the next-hop property of this route object.
236    ///
237    /// @next_hop (if non-[`None`]) must be a valid address of @self's family. If you
238    /// aren't sure you have a valid address, use nm_utils_ipaddr_valid() to check
239    /// it.
240    /// ## `next_hop`
241    /// the route's next hop, as a string
242    #[doc(alias = "nm_ip_route_set_next_hop")]
243    pub fn set_next_hop(&self, next_hop: Option<&str>) {
244        unsafe {
245            ffi::nm_ip_route_set_next_hop(self.to_glib_none().0, next_hop.to_glib_none().0);
246        }
247    }
248
249    //#[doc(alias = "nm_ip_route_set_next_hop_binary")]
250    //pub fn set_next_hop_binary(&self, next_hop: /*Unimplemented*/Option<Basic: Pointer>) {
251    //    unsafe { TODO: call ffi:nm_ip_route_set_next_hop_binary() }
252    //}
253
254    /// Sets the prefix property of this route object.
255    /// ## `prefix`
256    /// the route prefix
257    #[doc(alias = "nm_ip_route_set_prefix")]
258    pub fn set_prefix(&self, prefix: u32) {
259        unsafe {
260            ffi::nm_ip_route_set_prefix(self.to_glib_none().0, prefix);
261        }
262    }
263
264    //#[cfg(feature = "v1_8")]
265    //#[cfg_attr(docsrs, doc(cfg(feature = "v1_8")))]
266    //#[doc(alias = "nm_ip_route_attribute_validate")]
267    //pub fn attribute_validate(name: &str, value: /*Ignored*/&glib::Variant, family: i32) -> Result<bool, glib::Error> {
268    //    unsafe { TODO: call ffi:nm_ip_route_attribute_validate() }
269    //}
270
271    ///
272    /// # Returns
273    ///
274    /// the specifiers for route attributes
275    #[cfg(feature = "v1_8")]
276    #[cfg_attr(docsrs, doc(cfg(feature = "v1_8")))]
277    #[doc(alias = "nm_ip_route_get_variant_attribute_spec")]
278    #[doc(alias = "get_variant_attribute_spec")]
279    pub fn variant_attribute_spec() -> VariantAttributeSpec {
280        assert_initialized_main_thread!();
281        unsafe {
282            from_glib_none(ffi::nm_ip_route_get_variant_attribute_spec())
283        }
284    }
285}
286
287impl PartialEq for IPRoute {
288    #[inline]
289    fn eq(&self, other: &Self) -> bool {
290        self.equal(other)
291    }
292}
293
294impl Eq for IPRoute {}