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_22")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
use crate::{IPAddressCmpFlags};
use glib::{translate::*};

glib::wrapper! {
    #[derive(Debug, PartialOrd, Ord, Hash)]
    pub struct IPAddress(Shared<ffi::NMIPAddress>);

    match fn {
        ref => |ptr| ffi::nm_ip_address_ref(ptr),
        unref => |ptr| ffi::nm_ip_address_unref(ptr),
        type_ => || ffi::nm_ip_address_get_type(),
    }
}

impl IPAddress {
    /// Creates a new #NMIPAddress object.
    /// ## `family`
    /// the IP address family (<literal>AF_INET</literal> or
    ///   <literal>AF_INET6</literal>)
    /// ## `addr`
    /// the IP address
    /// ## `prefix`
    /// the address prefix length
    ///
    /// # Returns
    ///
    /// the new #NMIPAddress object, or [`None`] on error
    #[doc(alias = "nm_ip_address_new")]
    pub fn new(family: i32, addr: &str, prefix: u32) -> Result<IPAddress, glib::Error> {
        assert_initialized_main_thread!();
        unsafe {
            let mut error = std::ptr::null_mut();
            let ret = ffi::nm_ip_address_new(family, addr.to_glib_none().0, prefix, &mut error);
            if error.is_null() { Ok(from_glib_full(ret)) } else { Err(from_glib_full(error)) }
        }
    }

    //#[doc(alias = "nm_ip_address_new_binary")]
    //pub fn new_binary(family: i32, addr: /*Unimplemented*/Option<Basic: Pointer>, prefix: u32) -> Result<IPAddress, glib::Error> {
    //    unsafe { TODO: call ffi:nm_ip_address_new_binary() }
    //}

    /// Note that with @cmp_flags #NM_IP_ADDRESS_CMP_FLAGS_WITH_ATTRS, there
    /// is no total order for comparing GVariant. That means, if the two addresses
    /// only differ by their attributes, the sort order is undefined and the return
    /// value only indicates equality.
    /// ## `b`
    /// the #NMIPAddress to compare @address to.
    /// ## `cmp_flags`
    /// the #NMIPAddressCmpFlags that indicate what to compare.
    ///
    /// # Returns
    ///
    /// 0 if the two objects have the same values (according to their flags)
    ///   or a integer indicating the compare order.
    #[cfg(feature = "v1_22")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
    #[doc(alias = "nm_ip_address_cmp_full")]
    pub fn cmp_full(&self, b: &IPAddress, cmp_flags: IPAddressCmpFlags) -> i32 {
        unsafe {
            ffi::nm_ip_address_cmp_full(self.to_glib_none().0, b.to_glib_none().0, cmp_flags.into_glib())
        }
    }

    /// Creates a copy of @self
    ///
    /// # Returns
    ///
    /// a copy of @self
    ///
    /// This API was part of public headers before 1.32.0 but
    /// was erroneously not exported in the ABI. It is thus only
    /// usable since 1.32.0.
    #[cfg(feature = "v1_32")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_32")))]
    #[doc(alias = "nm_ip_address_dup")]
#[must_use]
    pub fn dup(&self) -> IPAddress {
        unsafe {
            from_glib_full(ffi::nm_ip_address_dup(self.to_glib_none().0))
        }
    }

    #[doc(alias = "nm_ip_address_equal")]
     fn equal(&self, other: &IPAddress) -> bool {
        unsafe {
            from_glib(ffi::nm_ip_address_equal(self.to_glib_none().0, other.to_glib_none().0))
        }
    }

    /// Gets the IP address property of this address object.
    ///
    /// # Returns
    ///
    /// the IP address
    #[doc(alias = "nm_ip_address_get_address")]
    #[doc(alias = "get_address")]
    pub fn address(&self) -> glib::GString {
        unsafe {
            from_glib_none(ffi::nm_ip_address_get_address(self.to_glib_none().0))
        }
    }

    //#[doc(alias = "nm_ip_address_get_address_binary")]
    //#[doc(alias = "get_address_binary")]
    //pub fn address_binary(&self, addr: /*Unimplemented*/Option<Basic: Pointer>) {
    //    unsafe { TODO: call ffi:nm_ip_address_get_address_binary() }
    //}

    //#[doc(alias = "nm_ip_address_get_attribute")]
    //#[doc(alias = "get_attribute")]
    //pub fn attribute(&self, name: &str) -> /*Ignored*/glib::Variant {
    //    unsafe { TODO: call ffi:nm_ip_address_get_attribute() }
    //}

    /// Gets an array of attribute names defined on @self.
    ///
    /// # Returns
    ///
    /// a [`None`]-terminated array of attribute names,
    #[doc(alias = "nm_ip_address_get_attribute_names")]
    #[doc(alias = "get_attribute_names")]
    pub fn attribute_names(&self) -> Vec<glib::GString> {
        unsafe {
            FromGlibPtrContainer::from_glib_full(ffi::nm_ip_address_get_attribute_names(self.to_glib_none().0))
        }
    }

    /// Gets the IP address family (eg, AF_INET) property of this address
    /// object.
    ///
    /// # Returns
    ///
    /// the IP address family
    #[doc(alias = "nm_ip_address_get_family")]
    #[doc(alias = "get_family")]
    pub fn family(&self) -> i32 {
        unsafe {
            ffi::nm_ip_address_get_family(self.to_glib_none().0)
        }
    }

    /// Gets the IP address prefix (ie "24" or "30" etc) property of this address
    /// object.
    ///
    /// # Returns
    ///
    /// the IP address prefix
    #[doc(alias = "nm_ip_address_get_prefix")]
    #[doc(alias = "get_prefix")]
    pub fn prefix(&self) -> u32 {
        unsafe {
            ffi::nm_ip_address_get_prefix(self.to_glib_none().0)
        }
    }

    /// Sets the IP address property of this address object.
    ///
    /// @addr must be a valid address of @self's family. If you aren't sure you
    /// have a valid address, use nm_utils_ipaddr_valid() to check it.
    /// ## `addr`
    /// the IP address, as a string
    #[doc(alias = "nm_ip_address_set_address")]
    pub fn set_address(&self, addr: &str) {
        unsafe {
            ffi::nm_ip_address_set_address(self.to_glib_none().0, addr.to_glib_none().0);
        }
    }

    //#[doc(alias = "nm_ip_address_set_address_binary")]
    //pub fn set_address_binary(&self, addr: /*Unimplemented*/Option<Basic: Pointer>) {
    //    unsafe { TODO: call ffi:nm_ip_address_set_address_binary() }
    //}

    //#[doc(alias = "nm_ip_address_set_attribute")]
    //pub fn set_attribute(&self, name: &str, value: /*Ignored*/Option<&glib::Variant>) {
    //    unsafe { TODO: call ffi:nm_ip_address_set_attribute() }
    //}

    /// Sets the IP address prefix property of this address object.
    /// ## `prefix`
    /// the IP address prefix
    #[doc(alias = "nm_ip_address_set_prefix")]
    pub fn set_prefix(&self, prefix: u32) {
        unsafe {
            ffi::nm_ip_address_set_prefix(self.to_glib_none().0, prefix);
        }
    }
}

impl PartialEq for IPAddress {
    #[inline]
    fn eq(&self, other: &Self) -> bool {
        self.equal(other)
    }
}

impl Eq for IPAddress {}