polkit 0.19.0

High-level bindings for libpolkit-gobject-1
// Generated by gir (https://github.com/gtk-rs/gir @ 0e476ab5c1de)
// from /usr/share/gir-1.0 (@ ???)
// DO NOT EDIT

use glib::{prelude::*, translate::*};

glib::wrapper! {
    /// [`Identity`][crate::Identity] is an abstract type for representing one or more
    /// identities.
    ///
    /// # Implements
    ///
    /// [`IdentityExt`][trait@crate::prelude::IdentityExt]
    #[doc(alias = "PolkitIdentity")]
    pub struct Identity(Interface<ffi::PolkitIdentity, ffi::PolkitIdentityIface>);

    match fn {
        type_ => || ffi::polkit_identity_get_type(),
    }
}

impl Identity {
    pub const NONE: Option<&'static Identity> = None;

    /// Creates an object from `str` that implements the [`Identity`][crate::Identity]
    /// interface.
    /// ## `str`
    /// A string obtained from [`IdentityExt::to_string()`][crate::prelude::IdentityExt::to_string()].
    ///
    /// # Returns
    ///
    /// A [`Identity`][crate::Identity] or [`None`]
    /// if `error` is set. Free with `g_object_unref()`.
    #[doc(alias = "polkit_identity_from_string")]
    pub fn from_string(str: &str) -> Result<Option<Identity>, glib::Error> {
        unsafe {
            let mut error = std::ptr::null_mut();
            let ret = ffi::polkit_identity_from_string(str.to_glib_none().0, &mut error);
            if error.is_null() {
                Ok(from_glib_full(ret))
            } else {
                Err(from_glib_full(error))
            }
        }
    }
}

mod sealed {
    pub trait Sealed {}
    impl<T: super::IsA<super::Identity>> Sealed for T {}
}

/// Trait containing all [`struct@Identity`] methods.
///
/// # Implementors
///
/// [`Identity`][struct@crate::Identity], [`UnixGroup`][struct@crate::UnixGroup], [`UnixNetgroup`][struct@crate::UnixNetgroup], [`UnixUser`][struct@crate::UnixUser]
pub trait IdentityExt: IsA<Identity> + sealed::Sealed + 'static {
    #[doc(alias = "polkit_identity_equal")]
    fn equal(&self, b: &impl IsA<Identity>) -> bool {
        unsafe {
            from_glib(ffi::polkit_identity_equal(
                self.as_ref().to_glib_none().0,
                b.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "polkit_identity_hash")]
    fn hash(&self) -> u32 {
        unsafe { ffi::polkit_identity_hash(self.as_ref().to_glib_none().0) }
    }

    /// Serializes `self` to a string that can be used in
    /// [`Identity::from_string()`][crate::Identity::from_string()].
    ///
    /// # Returns
    ///
    /// A string representing `self`. Free with `g_free()`.
    #[doc(alias = "polkit_identity_to_string")]
    fn to_string(&self) -> glib::GString {
        unsafe {
            from_glib_full(ffi::polkit_identity_to_string(
                self.as_ref().to_glib_none().0,
            ))
        }
    }
}

impl<O: IsA<Identity>> IdentityExt for O {}