gio 0.9.0

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

use gio_sys;
#[cfg(any(feature = "v2_64", feature = "dox"))]
use glib::object::Cast;
use glib::object::IsA;
#[cfg(any(feature = "v2_64", feature = "dox"))]
use glib::signal::connect_raw;
#[cfg(any(feature = "v2_64", feature = "dox"))]
use glib::signal::SignalHandlerId;
use glib::translate::*;
#[cfg(any(feature = "v2_64", feature = "dox"))]
use glib_sys;
#[cfg(any(feature = "v2_64", feature = "dox"))]
use std::boxed::Box as Box_;
use std::fmt;
#[cfg(any(feature = "v2_64", feature = "dox"))]
use std::mem::transmute;
#[cfg(any(feature = "v2_64", feature = "dox"))]
use MemoryMonitorWarningLevel;

glib_wrapper! {
    pub struct MemoryMonitor(Interface<gio_sys::GMemoryMonitor>);

    match fn {
        get_type => || gio_sys::g_memory_monitor_get_type(),
    }
}

impl MemoryMonitor {
    #[cfg(any(feature = "v2_64", feature = "dox"))]
    pub fn dup_default() -> Option<MemoryMonitor> {
        unsafe { from_glib_full(gio_sys::g_memory_monitor_dup_default()) }
    }
}

pub const NONE_MEMORY_MONITOR: Option<&MemoryMonitor> = None;

pub trait MemoryMonitorExt: 'static {
    #[cfg(any(feature = "v2_64", feature = "dox"))]
    fn connect_low_memory_warning<F: Fn(&Self, MemoryMonitorWarningLevel) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId;
}

impl<O: IsA<MemoryMonitor>> MemoryMonitorExt for O {
    #[cfg(any(feature = "v2_64", feature = "dox"))]
    fn connect_low_memory_warning<F: Fn(&Self, MemoryMonitorWarningLevel) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn low_memory_warning_trampoline<
            P,
            F: Fn(&P, MemoryMonitorWarningLevel) + 'static,
        >(
            this: *mut gio_sys::GMemoryMonitor,
            level: gio_sys::GMemoryMonitorWarningLevel,
            f: glib_sys::gpointer,
        ) where
            P: IsA<MemoryMonitor>,
        {
            let f: &F = &*(f as *const F);
            f(
                &MemoryMonitor::from_glib_borrow(this).unsafe_cast_ref(),
                from_glib(level),
            )
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"low-memory-warning\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    low_memory_warning_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl fmt::Display for MemoryMonitor {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "MemoryMonitor")
    }
}