nm-rs 0.1.3

Rust bindings for the libnm library.
Documentation
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir
// from gtk-girs (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use crate::{ffi};
#[cfg(feature = "v1_18")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
use glib::{translate::*};

glib::wrapper! {
    #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
    pub struct BridgeVlan(Shared<ffi::NMBridgeVlan>);

    match fn {
        ref => |ptr| ffi::nm_bridge_vlan_ref(ptr),
        unref => |ptr| ffi::nm_bridge_vlan_unref(ptr),
        type_ => || ffi::nm_bridge_vlan_get_type(),
    }
}

impl BridgeVlan {
    /// Creates a new #NMBridgeVlan object for the given VLAN id range.
    /// Setting @vid_end to 0 is equivalent to setting it to @vid_start
    /// and creates a single-id VLAN.
    ///
    /// Since 1.42, ref-counting of #NMBridgeVlan is thread-safe.
    /// ## `vid_start`
    /// the start VLAN id, must be between 1 and 4094.
    /// ## `vid_end`
    /// the end VLAN id, must be 0 or between @vid_start and 4094.
    ///
    /// # Returns
    ///
    /// the new #NMBridgeVlan object.
    #[cfg(feature = "v1_18")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
    #[doc(alias = "nm_bridge_vlan_new")]
    pub fn new(vid_start: u16, vid_end: u16) -> BridgeVlan {
        assert_initialized_main_thread!();
        unsafe {
            from_glib_full(ffi::nm_bridge_vlan_new(vid_start, vid_end))
        }
    }

    /// Compare two bridge VLAN objects.
    /// ## `b`
    /// another #NMBridgeVlan
    ///
    /// # Returns
    ///
    /// zero of the two instances are equivalent or
    ///   a non-zero integer otherwise. This defines a total ordering
    ///   over the VLANs. Whether a VLAN is sealed or not does not
    ///   affect the comparison.
    #[cfg(feature = "v1_18")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
    #[doc(alias = "nm_bridge_vlan_cmp")]
    pub fn cmp(&self, b: &BridgeVlan) -> i32 {
        unsafe {
            ffi::nm_bridge_vlan_cmp(self.to_glib_none().0, b.to_glib_none().0)
        }
    }

    /// Gets the VLAN id range.
    ///
    /// # Returns
    ///
    /// [`true`] is the VLAN specifies a range, [`false`] if it is
    /// a single-id VLAN.
    ///
    /// ## `vid_start`
    /// location to store the VLAN id range start.
    ///
    /// ## `vid_end`
    /// location to store the VLAN id range end
    #[cfg(feature = "v1_18")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
    #[doc(alias = "nm_bridge_vlan_get_vid_range")]
    #[doc(alias = "get_vid_range")]
    pub fn vid_range(&self) -> Option<(u16, u16)> {
        unsafe {
            let mut vid_start = std::mem::MaybeUninit::uninit();
            let mut vid_end = std::mem::MaybeUninit::uninit();
            let ret = from_glib(ffi::nm_bridge_vlan_get_vid_range(self.to_glib_none().0, vid_start.as_mut_ptr(), vid_end.as_mut_ptr()));
            if ret { Some((vid_start.assume_init(), vid_end.assume_init())) } else { None }
        }
    }

    /// Returns whether the VLAN is the PVID for the port.
    ///
    /// # Returns
    ///
    /// [`true`] if the VLAN is the PVID
    #[cfg(feature = "v1_18")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
    #[doc(alias = "nm_bridge_vlan_is_pvid")]
    pub fn is_pvid(&self) -> bool {
        unsafe {
            from_glib(ffi::nm_bridge_vlan_is_pvid(self.to_glib_none().0))
        }
    }

    ///
    /// # Returns
    ///
    /// whether @self_ is sealed or not.
    #[cfg(feature = "v1_18")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
    #[doc(alias = "nm_bridge_vlan_is_sealed")]
    pub fn is_sealed(&self) -> bool {
        unsafe {
            from_glib(ffi::nm_bridge_vlan_is_sealed(self.to_glib_none().0))
        }
    }

    /// Returns whether the VLAN is untagged.
    ///
    /// # Returns
    ///
    /// [`true`] if the VLAN is untagged, [`false`] otherwise
    #[cfg(feature = "v1_18")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
    #[doc(alias = "nm_bridge_vlan_is_untagged")]
    pub fn is_untagged(&self) -> bool {
        unsafe {
            from_glib(ffi::nm_bridge_vlan_is_untagged(self.to_glib_none().0))
        }
    }

    ///
    /// # Returns
    ///
    /// a clone of @self. This instance
    ///   is always unsealed.
    #[cfg(feature = "v1_18")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
    #[doc(alias = "nm_bridge_vlan_new_clone")]
#[must_use]
    pub fn new_clone(&self) -> BridgeVlan {
        unsafe {
            from_glib_full(ffi::nm_bridge_vlan_new_clone(self.to_glib_none().0))
        }
    }

    /// Seal the #NMBridgeVlan instance. Afterwards, it is a bug
    /// to call all functions that modify the instance (except ref/unref).
    /// A sealed instance cannot be unsealed again, but you can create
    /// an unsealed copy with nm_bridge_vlan_new_clone().
    #[cfg(feature = "v1_18")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
    #[doc(alias = "nm_bridge_vlan_seal")]
    pub fn seal(&self) {
        unsafe {
            ffi::nm_bridge_vlan_seal(self.to_glib_none().0);
        }
    }

    /// Change the value of the PVID property of the VLAN. It
    /// is invalid to set the value to [`true`] for non-single-id
    /// VLANs.
    /// ## `value`
    /// the new value
    #[cfg(feature = "v1_18")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
    #[doc(alias = "nm_bridge_vlan_set_pvid")]
    pub fn set_pvid(&self, value: bool) {
        unsafe {
            ffi::nm_bridge_vlan_set_pvid(self.to_glib_none().0, value.into_glib());
        }
    }

    /// Change the value of the untagged property of the VLAN.
    /// ## `value`
    /// the new value
    #[cfg(feature = "v1_18")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
    #[doc(alias = "nm_bridge_vlan_set_untagged")]
    pub fn set_untagged(&self, value: bool) {
        unsafe {
            ffi::nm_bridge_vlan_set_untagged(self.to_glib_none().0, value.into_glib());
        }
    }

    /// Convert a `NMBridgeVlan` to a string.
    ///
    /// # Returns
    ///
    /// formatted string or [`None`]
    #[cfg(feature = "v1_18")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
    #[doc(alias = "nm_bridge_vlan_to_str")]
    pub fn to_str(&self) -> Result<glib::GString, glib::Error> {
        unsafe {
            let mut error = std::ptr::null_mut();
            let ret = ffi::nm_bridge_vlan_to_str(self.to_glib_none().0, &mut error);
            if error.is_null() { Ok(from_glib_full(ret)) } else { Err(from_glib_full(error)) }
        }
    }

    /// Parses the string representation of the queueing
    /// discipline to a `NMBridgeVlan` instance.
    /// ## `str`
    /// the string representation of a bridge VLAN
    ///
    /// # Returns
    ///
    /// the `NMBridgeVlan` or [`None`]
    #[cfg(feature = "v1_18")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
    #[doc(alias = "nm_bridge_vlan_from_str")]
    pub fn from_str(str: &str) -> Result<BridgeVlan, glib::Error> {
        assert_initialized_main_thread!();
        unsafe {
            let mut error = std::ptr::null_mut();
            let ret = ffi::nm_bridge_vlan_from_str(str.to_glib_none().0, &mut error);
            if error.is_null() { Ok(from_glib_full(ret)) } else { Err(from_glib_full(error)) }
        }
    }
}