gio/auto/
credentials.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use gio_sys;
6use glib::translate::*;
7use glib::GString;
8use std::fmt;
9use std::ptr;
10use Error;
11
12glib_wrapper! {
13    pub struct Credentials(Object<gio_sys::GCredentials, gio_sys::GCredentialsClass, CredentialsClass>);
14
15    match fn {
16        get_type => || gio_sys::g_credentials_get_type(),
17    }
18}
19
20impl Credentials {
21    pub fn new() -> Credentials {
22        unsafe { from_glib_full(gio_sys::g_credentials_new()) }
23    }
24
25    //pub fn get_native(&self, native_type: CredentialsType) -> /*Unimplemented*/Option<Fundamental: Pointer> {
26    //    unsafe { TODO: call gio_sys:g_credentials_get_native() }
27    //}
28
29    #[cfg(any(unix, feature = "dox"))]
30    pub fn get_unix_pid(&self) -> Result<i32, Error> {
31        unsafe {
32            let mut error = ptr::null_mut();
33            let ret = gio_sys::g_credentials_get_unix_pid(self.to_glib_none().0, &mut error);
34            if error.is_null() {
35                Ok(ret)
36            } else {
37                Err(from_glib_full(error))
38            }
39        }
40    }
41
42    #[cfg(any(unix, feature = "dox"))]
43    pub fn get_unix_user(&self) -> Result<(), Error> {
44        unsafe {
45            let mut error = ptr::null_mut();
46            let _ = gio_sys::g_credentials_get_unix_user(self.to_glib_none().0, &mut error);
47            if error.is_null() {
48                Ok(())
49            } else {
50                Err(from_glib_full(error))
51            }
52        }
53    }
54
55    pub fn is_same_user(&self, other_credentials: &Credentials) -> Result<(), Error> {
56        unsafe {
57            let mut error = ptr::null_mut();
58            let _ = gio_sys::g_credentials_is_same_user(
59                self.to_glib_none().0,
60                other_credentials.to_glib_none().0,
61                &mut error,
62            );
63            if error.is_null() {
64                Ok(())
65            } else {
66                Err(from_glib_full(error))
67            }
68        }
69    }
70
71    //pub fn set_native(&self, native_type: CredentialsType, native: /*Unimplemented*/Fundamental: Pointer) {
72    //    unsafe { TODO: call gio_sys:g_credentials_set_native() }
73    //}
74
75    #[cfg(any(unix, feature = "dox"))]
76    pub fn set_unix_user(&self, uid: u32) -> Result<(), Error> {
77        unsafe {
78            let mut error = ptr::null_mut();
79            let _ = gio_sys::g_credentials_set_unix_user(self.to_glib_none().0, uid, &mut error);
80            if error.is_null() {
81                Ok(())
82            } else {
83                Err(from_glib_full(error))
84            }
85        }
86    }
87
88    pub fn to_string(&self) -> GString {
89        unsafe { from_glib_full(gio_sys::g_credentials_to_string(self.to_glib_none().0)) }
90    }
91}
92
93impl Default for Credentials {
94    fn default() -> Self {
95        Self::new()
96    }
97}
98
99impl fmt::Display for Credentials {
100    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
101        write!(f, "Credentials")
102    }
103}