nm_rs/auto/
setting_ovs_external_ids.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,Setting};
7use glib::{prelude::*};
8#[cfg(feature = "v1_30")]
9#[cfg_attr(docsrs, doc(cfg(feature = "v1_30")))]
10use glib::{signal::{connect_raw, SignalHandlerId},translate::*};
11#[cfg(feature = "v1_30")]
12#[cfg_attr(docsrs, doc(cfg(feature = "v1_30")))]
13use std::{boxed::Box as Box_};
14
15glib::wrapper! {
16    /// OVS External IDs Settings
17    ///
18    /// ## Properties
19    ///
20    ///
21    /// #### `data`
22    ///  A dictionary of key/value pairs with external-ids for OVS.
23    ///
24    /// Readable | Writeable
25    /// <details><summary><h4>Setting</h4></summary>
26    ///
27    ///
28    /// #### `name`
29    ///  The setting's name, which uniquely identifies the setting within the
30    /// connection.  Each setting type has a name unique to that type, for
31    /// example "ppp" or "802-11-wireless" or "802-3-ethernet".
32    ///
33    /// Readable
34    /// </details>
35    ///
36    /// # Implements
37    ///
38    /// [`SettingExt`][trait@crate::prelude::SettingExt]
39    #[doc(alias = "NMSettingOvsExternalIDs")]
40    pub struct SettingOvsExternalIDs(Object<ffi::NMSettingOvsExternalIDs, ffi::NMSettingOvsExternalIDsClass>) @extends Setting;
41
42    match fn {
43        type_ => || ffi::nm_setting_ovs_external_ids_get_type(),
44    }
45}
46
47impl SettingOvsExternalIDs {
48    /// Creates a new #NMSettingOvsExternalIDs object with default values.
49    ///
50    /// # Returns
51    ///
52    /// the new empty
53    /// #NMSettingOvsExternalIDs object
54    #[cfg(feature = "v1_30")]
55    #[cfg_attr(docsrs, doc(cfg(feature = "v1_30")))]
56    #[doc(alias = "nm_setting_ovs_external_ids_new")]
57    pub fn new() -> SettingOvsExternalIDs {
58        assert_initialized_main_thread!();
59        unsafe {
60            from_glib_full(ffi::nm_setting_ovs_external_ids_new())
61        }
62    }
63
64            // rustdoc-stripper-ignore-next
65            /// Creates a new builder-pattern struct instance to construct [`SettingOvsExternalIDs`] objects.
66            ///
67            /// This method returns an instance of [`SettingOvsExternalIDsBuilder`](crate::builders::SettingOvsExternalIDsBuilder) which can be used to create [`SettingOvsExternalIDs`] objects.
68            pub fn builder() -> SettingOvsExternalIDsBuilder {
69                SettingOvsExternalIDsBuilder::new()
70            }
71        
72
73    /// ## `key`
74    /// the external-id to lookup
75    ///
76    /// # Returns
77    ///
78    /// the value associated with @key or [`None`] if no such
79    ///   value exists.
80    #[cfg(feature = "v1_30")]
81    #[cfg_attr(docsrs, doc(cfg(feature = "v1_30")))]
82    #[doc(alias = "nm_setting_ovs_external_ids_get_data")]
83    #[doc(alias = "get_data")]
84    pub fn data(&self, key: &str) -> glib::GString {
85        unsafe {
86            from_glib_none(ffi::nm_setting_ovs_external_ids_get_data(self.to_glib_none().0, key.to_glib_none().0))
87        }
88    }
89
90    ///
91    /// # Returns
92    ///
93    /// a
94    ///   [`None`]-terminated array containing each key from the table.
95    #[cfg(feature = "v1_30")]
96    #[cfg_attr(docsrs, doc(cfg(feature = "v1_30")))]
97    #[doc(alias = "nm_setting_ovs_external_ids_get_data_keys")]
98    #[doc(alias = "get_data_keys")]
99    pub fn data_keys(&self) -> Vec<glib::GString> {
100        unsafe {
101            let mut out_len = std::mem::MaybeUninit::uninit();
102            let ret = FromGlibContainer::from_glib_none_num(ffi::nm_setting_ovs_external_ids_get_data_keys(self.to_glib_none().0, out_len.as_mut_ptr()), out_len.assume_init() as _);
103            ret
104        }
105    }
106
107    /// ## `key`
108    /// the key to set
109    /// ## `val`
110    /// the value to set or [`None`] to clear a key.
111    #[cfg(feature = "v1_30")]
112    #[cfg_attr(docsrs, doc(cfg(feature = "v1_30")))]
113    #[doc(alias = "nm_setting_ovs_external_ids_set_data")]
114    #[doc(alias = "data")]
115    pub fn set_data(&self, key: &str, val: Option<&str>) {
116        unsafe {
117            ffi::nm_setting_ovs_external_ids_set_data(self.to_glib_none().0, key.to_glib_none().0, val.to_glib_none().0);
118        }
119    }
120
121    /// Checks whether @key is a valid key for OVS' external-ids.
122    /// This means, the key cannot be [`None`], not too large and valid ASCII.
123    /// Also, only digits and numbers are allowed with a few special
124    /// characters. They key must also not start with "NM.".
125    /// ## `key`
126    /// the key to check
127    ///
128    /// # Returns
129    ///
130    /// [`true`] if @key is a valid user data key.
131    #[cfg(feature = "v1_30")]
132    #[cfg_attr(docsrs, doc(cfg(feature = "v1_30")))]
133    #[doc(alias = "nm_setting_ovs_external_ids_check_key")]
134    pub fn check_key(key: Option<&str>) -> Result<(), glib::Error> {
135        assert_initialized_main_thread!();
136        unsafe {
137            let mut error = std::ptr::null_mut();
138            let is_ok = ffi::nm_setting_ovs_external_ids_check_key(key.to_glib_none().0, &mut error);
139            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
140            if error.is_null() { Ok(()) } else { Err(from_glib_full(error)) }
141        }
142    }
143
144    /// Checks whether @val is a valid user data value. This means,
145    /// value is not [`None`], not too large and valid UTF-8.
146    /// ## `val`
147    /// the value to check
148    ///
149    /// # Returns
150    ///
151    /// [`true`] if @val is a valid user data value.
152    #[cfg(feature = "v1_30")]
153    #[cfg_attr(docsrs, doc(cfg(feature = "v1_30")))]
154    #[doc(alias = "nm_setting_ovs_external_ids_check_val")]
155    pub fn check_val(val: Option<&str>) -> Result<(), glib::Error> {
156        assert_initialized_main_thread!();
157        unsafe {
158            let mut error = std::ptr::null_mut();
159            let is_ok = ffi::nm_setting_ovs_external_ids_check_val(val.to_glib_none().0, &mut error);
160            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
161            if error.is_null() { Ok(()) } else { Err(from_glib_full(error)) }
162        }
163    }
164
165    #[cfg(feature = "v1_30")]
166    #[cfg_attr(docsrs, doc(cfg(feature = "v1_30")))]
167    #[doc(alias = "data")]
168    pub fn connect_data_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
169        unsafe extern "C" fn notify_data_trampoline<F: Fn(&SettingOvsExternalIDs) + 'static>(this: *mut ffi::NMSettingOvsExternalIDs, _param_spec: glib::ffi::gpointer, f: glib::ffi::gpointer) {
170            let f: &F = &*(f as *const F);
171            f(&from_glib_borrow(this))
172        }
173        unsafe {
174            let f: Box_<F> = Box_::new(f);
175            connect_raw(self.as_ptr() as *mut _, c"notify::data".as_ptr() as *const _,
176                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(notify_data_trampoline::<F> as *const ())), Box_::into_raw(f))
177        }
178    }
179}
180
181#[cfg(feature = "v1_30")]
182#[cfg_attr(docsrs, doc(cfg(feature = "v1_30")))]
183impl Default for SettingOvsExternalIDs {
184                     fn default() -> Self {
185                         Self::new()
186                     }
187                 }
188
189// rustdoc-stripper-ignore-next
190        /// A [builder-pattern] type to construct [`SettingOvsExternalIDs`] objects.
191        ///
192        /// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
193#[must_use = "The builder must be built to be used"]
194pub struct SettingOvsExternalIDsBuilder {
195            builder: glib::object::ObjectBuilder<'static, SettingOvsExternalIDs>,
196        }
197
198        impl SettingOvsExternalIDsBuilder {
199        fn new() -> Self {
200            Self { builder: glib::object::Object::builder() }
201        }
202
203                        //    #[cfg(feature = "v1_30")]
204    #[cfg_attr(docsrs, doc(cfg(feature = "v1_30")))]
205    //pub fn data(self, data: /*Unimplemented*/HashTable TypeId { ns_id: 0, id: 28 }/TypeId { ns_id: 0, id: 28 }) -> Self {
206                        //    Self { builder: self.builder.property("data", data), }
207                        //}
208
209    // rustdoc-stripper-ignore-next
210    /// Build the [`SettingOvsExternalIDs`].
211    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
212    pub fn build(self) -> SettingOvsExternalIDs {
213assert_initialized_main_thread!();
214    self.builder.build() }
215}