gio/auto/
icon.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;
7use glib::object::IsA;
8use glib::translate::*;
9use glib::GString;
10use glib_sys;
11use std::fmt;
12use std::ptr;
13use Error;
14
15glib_wrapper! {
16    pub struct Icon(Interface<gio_sys::GIcon>);
17
18    match fn {
19        get_type => || gio_sys::g_icon_get_type(),
20    }
21}
22
23impl Icon {
24    pub fn deserialize(value: &glib::Variant) -> Option<Icon> {
25        unsafe { from_glib_full(gio_sys::g_icon_deserialize(value.to_glib_none().0)) }
26    }
27
28    pub fn hash(&self) -> u32 {
29        unsafe {
30            gio_sys::g_icon_hash(
31                ToGlibPtr::<*mut gio_sys::GIcon>::to_glib_none(self).0 as glib_sys::gconstpointer,
32            )
33        }
34    }
35
36    pub fn new_for_string(str: &str) -> Result<Icon, Error> {
37        unsafe {
38            let mut error = ptr::null_mut();
39            let ret = gio_sys::g_icon_new_for_string(str.to_glib_none().0, &mut error);
40            if error.is_null() {
41                Ok(from_glib_full(ret))
42            } else {
43                Err(from_glib_full(error))
44            }
45        }
46    }
47}
48
49pub const NONE_ICON: Option<&Icon> = None;
50
51pub trait IconExt: 'static {
52    fn equal<P: IsA<Icon>>(&self, icon2: Option<&P>) -> bool;
53
54    fn serialize(&self) -> Option<glib::Variant>;
55
56    fn to_string(&self) -> Option<GString>;
57}
58
59impl<O: IsA<Icon>> IconExt for O {
60    fn equal<P: IsA<Icon>>(&self, icon2: Option<&P>) -> bool {
61        unsafe {
62            from_glib(gio_sys::g_icon_equal(
63                self.as_ref().to_glib_none().0,
64                icon2.map(|p| p.as_ref()).to_glib_none().0,
65            ))
66        }
67    }
68
69    fn serialize(&self) -> Option<glib::Variant> {
70        unsafe { from_glib_full(gio_sys::g_icon_serialize(self.as_ref().to_glib_none().0)) }
71    }
72
73    fn to_string(&self) -> Option<GString> {
74        unsafe { from_glib_full(gio_sys::g_icon_to_string(self.as_ref().to_glib_none().0)) }
75    }
76}
77
78impl fmt::Display for Icon {
79    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
80        write!(f, "Icon")
81    }
82}